这是今年写的代码最长的题了,细节很多
这里有一个数据,可以面向数据debug
https://pan.baidu.com/s/1cCIwW8psGDASu2JdZawG3Q
题面在代码后面
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <queue>
using namespace std;
#define MAX_CITY 22
#define NO_FLAG 0
#define RED_FLAG 1
#define BLUE_FLAG 2
#define ALL_FLAG 3
#define SWORD 0
#define BOMB 1
#define ARROW 2
#define N_WUQI 3
#define CasNull 0
#define CasDragon 1
#define CasNinja 2
#define CasIceman 3
#define CasLion 4
#define CasWolf 5
const string SWushi[6] = {"NaN","dragon","ninja","iceman","lion","wolf"};
int CntCity;
int Now = 0;
class Wuqi;
class Wushi;
class City;
class Head;
class City {
private:
int flag;
int MClife;
int LastWinner;
int Arrow_Winner;
Wushi *RedWushi;
Wushi *BlueWushi;
public:
// static Fi
City():flag(NO_FLAG),MClife(0),LastWinner(NO_FLAG),Arrow_Winner(NO_FLAG) {
RedWushi = NULL;
BlueWushi = NULL;
}
friend void Init_City(int N);
friend void GetCityLife(Head &rd,Head &bl);
friend void Marched(Head &rd,Head &bl);
friend void Use_bomb();
friend void Use_arrow();
friend void Battle(Head &rd,Head &bl);
friend void Wushi_report();
void SetRedWushi(Wushi *p) {
RedWushi = p;
}
void SetBlueWushi(Wushi *p) {
BlueWushi = p;
}
void Add_Life(int x) {
MClife += x;
}
Wushi *GetRedWushi() {
return RedWushi;
}
Wushi *GetBlueWushi() {
return BlueWushi;
}
// friend class Wushi;
};
City MCity[MAX_CITY],NullCity;
void Init_City(int N) {
CntCity = N;
for (int i = 0; i <= CntCity+1; i++) {
MCity[i] = NullCity;
MCity[i].flag = NO_FLAG;
MCity[i].RedWushi = NULL;
MCity[i].BlueWushi = NULL;
}
}
//////////////////////////////////////////////////////////////////////////
class Wushi {
protected:
int id;
int life;
int city_id;
int Belong;
int nPower;
int CasFlag;
public:
static string Wuqi_name[];
Wushi(int m_id=0,int m_life=0,int m_nPower = 0,int m_Belong = 0):id(m_id),life(m_life),Belong(m_Belong),\
nPower(m_nPower),CasFlag(CasNull) {
if (Belong==RED_FLAG) city_id = 0;
else city_id = CntCity+1;
}
virtual void show() {}
virtual int Attact(Wushi *Enemy) = 0;
virtual void Hurted(int Power) = 0;
virtual void FightBack(Wushi *Enemy) = 0;
virtual void show_wuqi() = 0;
virtual void UseArrow() {}
virtual void YELL() {}
virtual void GetEnemyWuqi(Wushi *Enemy) {}
virtual int GetWuqiCas() {
return 0;
}
virtual int GetPower() {
return nPower;
}
virtual int GetSelfPower() {
return nPower;
}
virtual int GetrePower() {
return nPower/2;
}
virtual int GetLife() {
return life;
}
virtual vector<pair<int,int> > AllWuqi() {
vector<pair<int,int> > wqs;
return wqs;
}
bool Is_alive() {
return life > 0;
}
void Add_Life(int x) {
life += x;
}
virtual bool WillRun() {
return false;
}
int GetId() {
return id;
}
int GetCasFlag() {
return CasFlag;
}
// virtual int GetPower() {
// return nPower;
// }
void SetCasFlag(int m_CasFlag) {
CasFlag = m_CasFlag;
}
friend void Marched(Head &rd,Head &bl);
friend bool TestDie(Wushi *Bomber,Wushi *Enemy,bool IsFrist);
//friend void Use_arrow();
};
string Wushi::Wuqi_name[] = {"sword", "bomb","arrow"};
//////////////////////////////////////////////////////////////////////////
/**
* @brief The Dragon class
* dragon可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,
* 其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。dragon 在一次在它主动进攻的战斗结束后,如果还没有战死,
* 而且士气值大于0.8,就会欢呼。dragon每取得一次战斗的胜利(敌人被杀死),士气就会增加0.2,每经历一次未能获胜的战斗,士气值就会减少0.2。
* 士气增减发生在欢呼之前。
*/
class Dragon:public Wushi {
private:
int Wuqi;
int WuqiInf;
double Shiqi;
public:
Dragon(int m_id,int m_life,int m_nPower,int m_Belong,double m_Shiqi):Wushi(m_id,m_life,m_nPower,m_Belong),Shiqi(m_Shiqi){
Wuqi = m_id%3;
CasFlag = CasDragon;
if (Wuqi == ARROW) WuqiInf = 3;
if (Wuqi == SWORD) {
WuqiInf = static_cast<int>(nPower*0.2);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
}
void show() {
cout << "Its morale is " << setiosflags(ios::fixed) << setprecision(2) <<Shiqi << endl;
}
int GetWuqiCas() {
return 1<<Wuqi;
}
void UseArrow() {
WuqiInf--;
if (WuqiInf == 0)
Wuqi = N_WUQI;
}
void show_wuqi() {
cout << setfill('0') << setw(3) << Now << ":55" << (Belong==RED_FLAG?" red ":" blue ") \
<< SWushi[CasFlag] << " " << id << " has ";
if (Wuqi == N_WUQI) cout << "no weapon\n";
else if (Wuqi == SWORD) cout << "sword(" << WuqiInf << ")\n";
else if (Wuqi == BOMB) cout << "bomb\n";
else if (Wuqi == ARROW) cout << "arrow(" << WuqiInf << ")\n";
}
virtual int GetPower() {
int Power = nPower;
if (Wuqi == SWORD)
Power += WuqiInf;
return Power;
}
virtual int GetrePower() {
int Power = nPower/2;
if (Wuqi == SWORD)
Power += WuqiInf;
return Power;
}
void YELL() {
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " yelled in city " << city_id << endl;
}
int Attact(Wushi *Enemy) {
//011:40 blue lion 6 attacked red ninja 9 in city 4 with 28 elements and force 10
int Power = nPower;
if (Wuqi == SWORD) {
Power += WuqiInf;
WuqiInf = static_cast<int>(WuqiInf*0.8);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " attacked" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << " with " << life << " elements and force " << nPower << endl;
int tmplife = Enemy->GetLife();
Enemy->Hurted(Power);
//001:40 blue dragon 2 fought back against red lion 2 in city 1
if (Enemy->Is_alive() == 0) {
if(Enemy->GetCasFlag() == CasLion)
life += tmplife;
Shiqi += 0.2;
if (Shiqi > 0.8) {
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " yelled in city " << city_id << endl;
}
return 1;
} else {
Enemy->FightBack(this);
Shiqi -= 0.2;
if (Is_alive()) {
if (Shiqi > 0.8) {
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " yelled in city " << city_id << endl;
}
return 0;
}
else
return -1;
}
}
void Hurted(int Power) {
life -= Power;
if (life <= 0) {
life = 0;
//001:40 red lion 2 was killedin city1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " was killed in city " << city_id << endl;
}
// if (life > 0) FightBack();
}
void FightBack(Wushi *Enemy) {
int Power = nPower/2;
if (Wuqi == SWORD) {
Power += WuqiInf;
WuqiInf = static_cast<int>(WuqiInf*0.8);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
//001:40 blue dragon 2 fought back against red lion 2 in city 1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " fought back against" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << endl;
Enemy->Hurted(Power);
}
virtual vector<pair<int,int> > AllWuqi() {
vector<pair<int,int> > wqs;
if (Wuqi != N_WUQI) {
wqs.push_back(make_pair(Wuqi,WuqiInf));
}
return wqs;
}
};
/**
* @brief The Ninja class
* ninjia可以拥有两件武器。编号为n的ninjia降生时即获得编号为 n%3 和 (n+1)%3的武器。ninja 挨打了也从不反击敌人。
*/
class Ninja:public Wushi {
private:
int Wuqi1,Wuqi2;
int WuqiInf1,WuqiInf2;
public:
Ninja(int m_id,int m_life,int m_nPower,int m_Belong):Wushi(m_id,m_life,m_nPower,m_Belong) {
Wuqi1 = m_id%3;
Wuqi2 = (m_id+1)%3;
CasFlag = CasNinja;
if (Wuqi1 == ARROW) WuqiInf1 = 3;
if (Wuqi1 == SWORD) {
WuqiInf1 = static_cast<int>(nPower*0.2);
if (WuqiInf1 == 0) Wuqi1 = N_WUQI;
}
if (Wuqi2 == ARROW) WuqiInf2 = 3;
if (Wuqi2 == SWORD) {
WuqiInf2 = static_cast<int>(nPower*0.2);
if (WuqiInf2 == 0) Wuqi2 = N_WUQI;
}
}
int GetWuqiCas() {
return (1<<Wuqi1) | (1<<Wuqi2);
}
void UseArrow() {
if (Wuqi1 == ARROW) {
WuqiInf1--;
if (WuqiInf1 == 0)
Wuqi1 = N_WUQI;
}
if (Wuqi2 == ARROW) {
WuqiInf2--;
if (WuqiInf2 == 0)
Wuqi2 = N_WUQI;
}
}
void show_wuqi() {
cout << setfill('0') << setw(3) << Now << ":55" << (Belong==RED_FLAG?" red ":" blue ") \
<< SWushi[CasFlag] << " " << id << " has ";
if (Wuqi1 < Wuqi2) {
swap(Wuqi1,Wuqi2);
swap(WuqiInf1,WuqiInf2);
}
if (Wuqi1 == N_WUQI && Wuqi2 == N_WUQI)
cout << "no weapon\n";
else if(Wuqi1 == N_WUQI) {
if (Wuqi2 == ARROW) cout << "arrow(" << WuqiInf2 << ")\n";
if (Wuqi2 == BOMB) cout << "bomb\n";
if (Wuqi2 == SWORD) cout << "sword(" << WuqiInf2 << ")\n";
} else {
if (Wuqi1 == ARROW) cout << "arrow(" << WuqiInf1 << "),";
if (Wuqi1 == BOMB) cout << "bomb,";
if (Wuqi2 == BOMB) cout << "bomb\n";
if (Wuqi2 == SWORD) cout << "sword(" << WuqiInf2 << ")\n";
}
}
void show() {
// cout << "It has a " << Wuqi1 << " and a " << Wuqi2 << endl;
}
virtual int GetPower() {
int Power = nPower;
if (Wuqi1 == SWORD)
Power += WuqiInf1;
if (Wuqi2 == SWORD)
Power += WuqiInf2;
return Power;
}
virtual int GetrePower() {
return 0;
}
int Attact(Wushi *Enemy) {
//011:40 blue lion 6 attacked red ninja 9 in city 4 with 28 elements and force 10
int Power = nPower;
if (Wuqi1 == SWORD) {
Power += WuqiInf1;
WuqiInf1 = static_cast<int>(WuqiInf1*0.8);
if (WuqiInf1 == 0) Wuqi1 = N_WUQI;
}
if (Wuqi2 == SWORD) {
Power += WuqiInf2;
WuqiInf2 = static_cast<int>(WuqiInf2*0.8);
if (WuqiInf2 == 0) Wuqi2 = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " attacked" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << " with " << life << " elements and force " << nPower << endl;
int tmplife = Enemy->GetLife();
Enemy->Hurted(Power);
//001:40 blue dragon 2 fought back against red lion 2 in city 1
if (Enemy->Is_alive()) {
Enemy->FightBack(this);
if (Is_alive()) return 0;
return -1;
} else {
if(Enemy->GetCasFlag() == CasLion)
life += tmplife;
return 1;
}
}
void Hurted(int Power) {
life -= Power;
if (life <= 0) {
life = 0;
//001:40 red lion 2 was killed in city 1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " was killed in city " << city_id << endl;
}
// if (life > 0) FightBack();
}
void FightBack(Wushi *Enemy) {
}
virtual vector<pair<int,int> > AllWuqi() {
vector<pair<int,int> > wqs;
if (Wuqi1 != N_WUQI)
wqs.push_back(make_pair(Wuqi1,WuqiInf1));
if (Wuqi2 != N_WUQI)
wqs.push_back(make_pair(Wuqi2,WuqiInf2));
return wqs;
}
};
/**
* @brief The Iceman class
* iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。
* iceman 每前进两步,在第2步完成的时候,生命值会减少9,攻击力会增加20。
* 但是若生命值减9后会小于等于0,则生命值不减9,而是变为1。即iceman不会因走多了而死。
*/
class Iceman:public Wushi {
private:
int Wuqi;
int WuqiInf;
public:
Iceman(int m_id,int m_life,int m_nPower,int m_Belong):Wushi(m_id,m_life,m_nPower,m_Belong) {
Wuqi = m_id%3;
CasFlag = CasIceman;
if (Wuqi == ARROW) WuqiInf = 3;
if (Wuqi == SWORD) {
WuqiInf = static_cast<int>(nPower*0.2);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
}
/* int StepCnt() {
if (Belong==RED_FLAG)
return city_id / 2;
else
return (CntCity+1-city_id) / 2;
}*/
int GetWuqiCas() {
return 1<<Wuqi;
}
void UseArrow() {
WuqiInf--;
if (WuqiInf == 0)
Wuqi = N_WUQI;
}
void show_wuqi() {
cout << setfill('0') << setw(3) << Now << ":55" << (Belong==RED_FLAG?" red ":" blue ") \
<< SWushi[CasFlag] << " " << id << " has ";
if (Wuqi == N_WUQI) cout << "no weapon\n";
else if (Wuqi == SWORD) cout << "sword(" << WuqiInf << ")\n";
else if (Wuqi == BOMB) cout << "bomb\n";
else if (Wuqi == ARROW) cout << "arrow(" << WuqiInf << ")\n";
}
void show() {
// cout << "It has a " << Wuqi << endl;
}
virtual int GetPower() {
//int detPower = StepCnt() * 20;
int Power = nPower;
if (Wuqi == SWORD)
Power += WuqiInf;
return Power;
}
/* virtual int GetSelfPower() {
int detPower = StepCnt() * 20;
// cout<<"UUUU"<<city_id<<"ggg";
int Power = nPower + detPower;
return Power;
} */
virtual int GetrePower() {
//int detPower = StepCnt() * 20;
//int Power = (nPower + detPower)/2;
int Power = nPower/2;
if (Wuqi == SWORD)
Power += WuqiInf;
return Power;
}
int Attact(Wushi *Enemy) {
//011:40 blue lion 6 attacked red ninja 9 in city 4 with 28 elements and force 10
// int detPower = StepCnt() * 20;
int Power = nPower;
if (Wuqi == SWORD) {
Power += WuqiInf;
WuqiInf = static_cast<int>(WuqiInf*0.8);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " attacked" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << " with " << life << " elements and force " << nPower << endl;
int tmplife = Enemy->GetLife();
Enemy->Hurted(Power);
//001:40 blue dragon 2 fought back against red lion 2 in city 1
if (Enemy->Is_alive()) {
Enemy->FightBack(this);
if (Is_alive()) return 0;
return -1;
} else {
if(Enemy->GetCasFlag() == CasLion)
life += tmplife;
return 1;
}
}
int GetLife() {
// int detLife = StepCnt()*9;
// int mlife = max(1,life-detLife);
//cout<<"llllyj"<<detLife<<" "<<life<<" ";
return life;
}
void Hurted(int Power) {
life -= Power;
if (life <= 0) {
life = 0;
life = 0;
//001:40 red lion 2 was killed in city 1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " was killed in city " << city_id << endl;
}
// if (life > 0) FightBack();
}
void FightBack(Wushi *Enemy) {
//001:40 blue dragon 2 fought back against red lion 2 in city 1
// int detPower = StepCnt() * 20;
int Power = (nPower)/2;
if (Wuqi == SWORD) {
Power += WuqiInf;
WuqiInf = static_cast<int>(WuqiInf*0.8);
if (WuqiInf == 0) Wuqi = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " fought back against" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << endl;
Enemy->Hurted(Power);
}
virtual vector<pair<int,int> > AllWuqi() {
vector<pair<int,int> > wqs;
if (Wuqi != N_WUQI)
wqs.push_back(make_pair(Wuqi,WuqiInf));
return wqs;
}
};
/**
* @brief The Lion class
* lion 有“忠诚度”这个属性,其初始值等于它降生之后其司令部剩余生命元的数目。
* 每经过一场未能杀死敌人的战斗,忠诚度就降低K。
* 忠诚度降至0或0以下,则该lion逃离战场,永远消失。
* 但是已经到达敌人司令部的lion不会逃跑。
* Lion在己方司令部可能逃跑。lion 若是战死,则其战斗前的生命值就会转移到对手身上。
* 所谓“战斗前”,就是每个小时的40分前的一瞬间。
*/
int Lion_K;
class Lion:public Wushi {
private:
int Cheng;
public:
Lion(int m_id,int m_life,int m_nPower,int m_Belong,int m_Cheng):Wushi(m_id,m_life,m_nPower,m_Belong),Cheng(m_Cheng){
CasFlag = CasLion;
}
void show() {
cout << "Its loyalty is " << Cheng << endl;
}
bool WillRun() {
if (Belong == RED_FLAG && city_id == CntCity+1) return false;
if (Belong == BLUE_FLAG && city_id == 0) return false;
return Cheng <= 0;
}
void show_wuqi() {
cout << setfill('0') << setw(3) << Now << ":55" << (Belong==RED_FLAG?" red ":" blue ") \
<< SWushi[CasFlag] << " " << id << " has " << "no weapon\n";
}
int Attact(Wushi *Enemy) {
//011:40 blue lion 6 attacked red ninja 9 in city 4 with 28 elements and force 10
int Power = nPower;
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " attacked" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << " with " << life << " elements and force " << nPower << endl;
int tmplife = Enemy->GetLife();
Enemy->Hurted(Power);
//001:40 blue dragon 2 fought back against red lion 2 in city 1
if (Enemy->Is_alive()) {
Cheng -= Lion_K;
int tmp = life;
Enemy->FightBack(this);
if (Is_alive()) return 0;
else {
Enemy->Add_Life(tmp);
return -1;
}
} else {
if(Enemy->GetCasFlag() == CasLion)
life += tmplife;
return 1;
}
}
void Hurted(int Power) {
life -= Power;
if (life <= 0) {
life = 0;
//001:40 red lion 2 was killed in city 1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " was killed in city " << city_id << endl;
}
// if (life > 0) FightBack();
}
void FightBack(Wushi *Enemy) {
//001:40 blue dragon 2 fought back against red lion 2 in city 1
int Power = nPower/2;
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " fought back against" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << endl;
Enemy->Hurted(Power);
if (Enemy->Is_alive())
Cheng -= Lion_K;
}
};
/**
* @brief The Wolf class
* wolf降生时没有武器,但是在战斗中如果获胜(杀死敌人),就会缴获敌人的武器,但自己已有的武器就不缴获了。
* 被缴获的武器当然不能算新的,已经被用到什么样了,就是什么样的。
*/
class Wolf:public Wushi {
private:
//vector<>
int Wuqi1,Wuqi2,Wuqi3;
int WuqiInf1,WuqiInf2,WuqiInf3;
public:
Wolf(int m_id,int m_life,int m_nPower,int m_Belong):Wushi(m_id,m_life,m_nPower,m_Belong) {
Wuqi1 = Wuqi2 = Wuqi3 = N_WUQI;
CasFlag = CasWolf;
}
int GetWuqiCas() {
return (1<<Wuqi1) | (1<<Wuqi2) | (1<<Wuqi3);
}
void UseArrow() {
if (Wuqi1 == ARROW) {
WuqiInf1--;
if (WuqiInf1 == 0)
Wuqi1 = N_WUQI;
}
if (Wuqi2 == ARROW) {
WuqiInf2--;
if (WuqiInf2 == 0)
Wuqi2 = N_WUQI;
}
if (Wuqi3 == ARROW) {
WuqiInf3--;
if (WuqiInf3 == 0)
Wuqi3 = N_WUQI;
}
}
void show_wuqi() {
cout << setfill('0') << setw(3) << Now << ":55" << (Belong==RED_FLAG?" red ":" blue ") \
<< SWushi[CasFlag] << " " << id << " has ";
if (Wuqi1 < Wuqi3) {
swap(Wuqi1,Wuqi3);
swap(WuqiInf1,WuqiInf3);
}
if (Wuqi2 < Wuqi3) {
swap(Wuqi2,Wuqi3);
swap(WuqiInf2,WuqiInf3);
}
if (Wuqi1 < Wuqi2) {
swap(Wuqi1,Wuqi2);
swap(WuqiInf1,WuqiInf2);
}
// 1 < 2 < 3
if (Wuqi3 == N_WUQI)
cout << "no weapon\n";
else if (Wuqi2 == N_WUQI) {
if (Wuqi3 == ARROW) cout << "arrow(" << WuqiInf3 << ")\n";
if (Wuqi3 == BOMB) cout << "bomb\n";
if (Wuqi3 == SWORD) cout << "sword(" << WuqiInf3 << ")\n";
} else if (Wuqi1 == N_WUQI) {
if (Wuqi2 == ARROW) cout << "arrow(" << WuqiInf2 << "),";
if (Wuqi2 == BOMB) cout << "bomb,";
if (Wuqi3 == BOMB) cout << "bomb\n";
if (Wuqi3 == SWORD) cout << "sword(" << WuqiInf3 << ")\n";
} else {
cout << "arrow(" << WuqiInf1 << "),";
cout << "bomb,";
cout << "sword(" << WuqiInf3 << ")\n";
}
}
void show() {}
virtual int GetPower() {
int Power = nPower;
if (Wuqi1 == SWORD)
Power += WuqiInf1;
if (Wuqi2 == SWORD)
Power += WuqiInf2;
if (Wuqi3 == SWORD)
Power += WuqiInf3;
return Power;
}
virtual int GetrePower() {
int Power = nPower/2;
if (Wuqi1 == SWORD)
Power += WuqiInf1;
if (Wuqi2 == SWORD)
Power += WuqiInf2;
if (Wuqi3 == SWORD)
Power += WuqiInf3;
return Power;
}
int Attact(Wushi *Enemy) {
//011:40 blue lion 6 attacked red ninja 9 in city 4 with 28 elements and force 10
int Power = nPower;
if (Wuqi1 == SWORD) {
Power += WuqiInf1;
WuqiInf1 = static_cast<int>(WuqiInf1*0.8);
if (WuqiInf1 == 0) Wuqi1 = N_WUQI;
}
if (Wuqi2 == SWORD) {
Power += WuqiInf2;
WuqiInf2 = static_cast<int>(WuqiInf2*0.8);
if (WuqiInf2 == 0) Wuqi2 = N_WUQI;
}
if (Wuqi3 == SWORD) {
Power += WuqiInf3;
WuqiInf3 = static_cast<int>(WuqiInf3*0.8);
if (WuqiInf3 == 0) Wuqi3 = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " attacked" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << " with " << life << " elements and force " << nPower << endl;
int tmplife = Enemy->GetLife();
Enemy->Hurted(Power);
//001:40 blue dragon 2 fought back against red lion 2 in city 1
if (Enemy->Is_alive()) {
Enemy->FightBack(this);
if (Is_alive()) return 0;
return -1;
} else {
if(Enemy->GetCasFlag() == CasLion)
life += tmplife;
GetEnemyWuqi(Enemy);
return 1;
}
}
void Hurted(int Power) {
life -= Power;
if (life <= 0) {
life = 0;
//001:40 red lion 2 was killed in city 1
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " was killed in city " << city_id << endl;
}
// if (life > 0) FightBack();
}
void FightBack(Wushi *Enemy) {
//001:40 blue dragon 2 fought back against red lion 2 in city 1
int Power = nPower/2;
if (Wuqi1 == SWORD) {
Power += WuqiInf1;
WuqiInf1 = static_cast<int>(WuqiInf1*0.8);
if (WuqiInf1 == 0) Wuqi1 = N_WUQI;
}
if (Wuqi2 == SWORD) {
Power += WuqiInf2;
WuqiInf2 = static_cast<int>(WuqiInf2*0.8);
if (WuqiInf2 == 0) Wuqi2 = N_WUQI;
}
if (Wuqi3 == SWORD) {
Power += WuqiInf3;
WuqiInf3 = static_cast<int>(WuqiInf3*0.8);
if (WuqiInf3 == 0) Wuqi3 = N_WUQI;
}
cout << setfill('0') << setw(3) << Now << ":40" << (Belong==RED_FLAG?" red " : " blue ") << SWushi[CasFlag] << " " \
<< id << " fought back against" << (Belong!=RED_FLAG?" red " : " blue ") << SWushi[Enemy->GetCasFlag()] << " "\
<< Enemy->GetId() << " in city " << city_id << endl;
Enemy->Hurted(Power);
if (Enemy->Is_alive() == 0)
GetEnemyWuqi(Enemy);
}
virtual vector<pair<int,int> > AllWuqi() {
vector<pair<int,int> > wqs;
if (Wuqi1 != N_WUQI)
wqs.push_back(make_pair(Wuqi1,WuqiInf1));
if (Wuqi2 != N_WUQI)
wqs.push_back(make_pair(Wuqi2,WuqiInf2));
if (Wuqi3 != N_WUQI)
wqs.push_back(make_pair(Wuqi3,WuqiInf3));
return wqs;
}
void GetEnemyWuqi(Wushi *Enemy) {
vector<pair<int,int> > tp = Enemy->AllWuqi();
for (int i = 0; i < tp.size(); i++) {
int wq = tp[i].first,wpf = tp[i].second;
if (wq!=Wuqi1 && wq!=Wuqi2 && wq != Wuqi3) {
if (Wuqi1 == N_WUQI) {
Wuqi1 = wq;
WuqiInf1 = wpf;
} else if (Wuqi2 == N_WUQI) {
Wuqi2 = wq;
WuqiInf2 = wpf;
} else if (Wuqi2 == N_WUQI) {
Wuqi2 = wq;
WuqiInf2 = wpf;
}
}
}
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////
int Winner = NO_FLAG;
class Head {
private:
static int cast[5];
static int Power[5];
static string SWushi[5];
int Mlife,pos[5];
bool isRed;
int cnt;
vector<Wushi*> Wushis;
public:
static void init();
Head(){}
Head(int m_M,bool m_isRed,int c0,int c1,int c2,int c3,int c4):Mlife(m_M),isRed(m_isRed),cnt(0){
pos[0] = c0;
pos[1] = c1;
pos[2] = c2;
pos[3] = c3;
pos[4] = c4;
// memset(Ct,0,sizeof Ct);
}
bool Made();
void RunAway();
//friend void WillRun();
Wushi* New_Wushi(int id);
int GetLastLife() {
return Mlife;
}
void AddLife(int x) {
Mlife += x;
}
};
int Head::cast[5];
int Head::Power[5];
string Head::SWushi[5] = {"dragon","ninja","iceman","lion","wolf"};
void Head::init() {
for (int k = 0; k < 5; k++)
cin >> Head::cast[k];
for (int k = 0; k < 5; k++)
cin >> Head::Power[k];
}
Wushi* Head::New_Wushi(int id) {
int Belong_ = isRed?RED_FLAG:BLUE_FLAG;
switch(id) {
case 0: return new Dragon(cnt,cast[0],Power[0],Belong_,1.0*Mlife/cast[0]);
case 1: return new Ninja(cnt,cast[1],Power[1],Belong_);
case 2: return new Iceman (cnt,cast[2],Power[2],Belong_);
case 3: return new Lion (cnt,cast[3],Power[3],Belong_,Mlife);
case 4: return new Wolf (cnt,cast[4],Power[4],Belong_);
}
}
bool Head::Made() {
int iid = pos[cnt%5];
if (Mlife < cast[iid]) return false;
// int Tp = Now;
cnt = cnt+1;
//cout << Now << " " << id << "\n";
// Ct[iid]++;
Mlife -= cast[iid];
cout << setfill('0') << setw(3) << Now << ":00" << (isRed?" red ":" blue ")\
<< SWushi[iid] << " " << cnt << " born\n";
Wushi *MyWs = New_Wushi(iid);
(*MyWs).show();
//Wushis.push_back(MyWs);
if(isRed) MCity[0].SetRedWushi(MyWs);
else MCity[CntCity+1].SetBlueWushi(MyWs);
}
void RunAway() {
/*
int st = 0, ed = Wushis.size()-1, det = 1;
if (isRed == 0) {
swap(st,ed);
det = -1;
}
for (int i = st; i <= ed; i+=det)
if (Wushis[i]->GetCasFlag() == CasLion)
if (Wushis[i]->WillRun()) {
//000:05 blue lion 1 ran away
cout << setfill('0') << setw(3) << Now << ":05" << (isRed?" red ":" blue ")\
<< "lion " << Wushis[i]->GetId() << " ran away\n";
Wushis[i]->SetCasFlag(CasNull);
}*/
if (MCity[0].GetRedWushi() != NULL)
if (MCity[0].GetRedWushi()->GetCasFlag() == CasLion)
if (MCity[0].GetRedWushi()->WillRun()) {
//000:05 blue lion 1 ran away
cout << setfill('0') << setw(3) << Now << ":05" << " red "\
<< "lion " << MCity[0].GetRedWushi()->GetId() << " ran away\n";
MCity[0].SetRedWushi(NULL);
}
for (int i = 1; i <= CntCity; i++) {
if (MCity[i].GetRedWushi() != NULL)
if (MCity[i].GetRedWushi()->GetCasFlag() == CasLion)
if (MCity[i].GetRedWushi()->WillRun()) {
//000:05 blue lion 1 ran away
cout << setfill('0') << setw(3) << Now << ":05" << " red "\
<< "lion " << MCity[i].GetRedWushi()->GetId() << " ran away\n";
MCity[i].SetRedWushi(NULL);
}
if (MCity[i].GetBlueWushi() != NULL)
if (MCity[i].GetBlueWushi()->GetCasFlag() == CasLion)
if (MCity[i].GetBlueWushi()->WillRun()) {
//000:05 blue lion 1 ran away
cout << setfill('0') << setw(3) << Now << ":05" << " blue "\
<< "lion " << MCity[i].GetBlueWushi()->GetId() << " ran away\n";
MCity[i].SetBlueWushi(NULL);
}
}
if (MCity[CntCity+1].GetBlueWushi() != NULL)
if (MCity[CntCity+1].GetBlueWushi()->GetCasFlag() == CasLion)
if (MCity[CntCity+1].GetBlueWushi()->WillRun()) {
//000:05 blue lion 1 ran away
cout << setfill('0') << setw(3) << Now << ":05" << " blue "\
<< "lion " << MCity[CntCity+1].GetBlueWushi()->GetId() << " ran away\n";
MCity[CntCity+1].SetBlueWushi(NULL);
}
}
//同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地。
void Marched(Head &rd,Head &bl) {
//iceman 每前进两步,在第2步完成的时候,生命值会减少9,攻击力会增加20。
for (int i = 0; i <= CntCity+1; i++) {
if (i!=CntCity+1 && MCity[i].GetRedWushi() != NULL)
if (MCity[i].GetRedWushi()->GetCasFlag() == CasIceman)
if (i&1) {
MCity[i].GetRedWushi()->life = max(1,MCity[i].GetRedWushi()->life-9);
MCity[i].GetRedWushi()->nPower += 20;
}
if (i!=0 && MCity[i].GetBlueWushi() != NULL)
if (MCity[i].GetBlueWushi()->GetCasFlag() == CasIceman)
if ((CntCity+1-i)&1) {
MCity[i].GetBlueWushi()->life = max(1,MCity[i].GetBlueWushi()->life-9);
MCity[i].GetBlueWushi()->nPower += 20;
}
}
for (int i = 0; i <= CntCity+1; i++) {
if (i!=CntCity+1 && MCity[i].GetRedWushi() != NULL)
MCity[i].GetRedWushi()->city_id = i+1;
if (i!=0 && MCity[i].GetBlueWushi() != NULL)
MCity[i].GetBlueWushi()->city_id = i-1;
}
Wushi *per = NULL, *nxt = NULL;
if (MCity[1].BlueWushi != NULL) {
//001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
Wushi *tmp = MCity[1].BlueWushi;
MCity[1].BlueWushi = NULL;
cout << setfill('0') << setw(3) << Now << ":10" << " blue " << SWushi[tmp->GetCasFlag()] << " " \
<< tmp->GetId() << " reached red headquarter with " << tmp->GetLife() << " elements and force " << tmp->GetSelfPower() << endl;
if (MCity[0].BlueWushi == NULL) MCity[0].BlueWushi = tmp;
else {
Winner = BLUE_FLAG;
cout << setfill('0') << setw(3) << Now << ":10" << " red headquarter was taken\n";
}
}
per = MCity[0].RedWushi;
MCity[0].RedWushi = NULL;
for (int i = 1; i <= CntCity; i++) {
if (per != NULL) {
// 000:10 red iceman 1 marched to city 1 with 20 elements and force 30
cout << setfill('0') << setw(3) << Now << ":10" << " red " << SWushi[per->GetCasFlag()] << " " \
<< per->GetId() << " marched to city " << i << " with " << per->GetLife() << " elements and force " << per->GetSelfPower() << endl;
}
Wushi* tmp = MCity[i].RedWushi;
MCity[i].RedWushi = per;
per = tmp;
nxt = MCity[i+1].BlueWushi;
MCity[i+1].BlueWushi = NULL;
if(nxt != NULL) {
// 000:10 red iceman 1 marched to city 1 with 20 elements and force 30
cout << setfill('0') << setw(3) << Now << ":10" << " blue " << SWushi[nxt->GetCasFlag()] << " " \
<< nxt->GetId() << " marched to city " << i << " with " << nxt->GetLife() << " elements and force " << nxt->GetSelfPower() << endl;
MCity[i].BlueWushi = nxt;
}
}
//per = MCity[CntCity].RedWushi;
if (per != NULL) {
cout << setfill('0') << setw(3) << Now << ":10" << " red " << SWushi[per->GetCasFlag()] << " " \
<< per->GetId() << " reached blue headquarter with " << per->GetLife() << " elements and force " << per->GetSelfPower() << endl;
if (MCity[CntCity+1].RedWushi == NULL) MCity[CntCity+1].RedWushi = per;
else {
Winner = RED_FLAG;
cout << setfill('0') << setw(3) << Now << ":10" << " blue headquarter was taken\n";
}
}
}
void GetCityLife(Head &rd,Head &bl) {
for (int i = 1; i <= CntCity; i++)
if (MCity[i].MClife > 0) {
if (MCity[i].GetBlueWushi() == NULL && MCity[i].GetRedWushi() != NULL) {
//000:30 blue lion 1 earned 10 elements for his headquarter
cout << setfill('0') << setw(3) << Now << ":30 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter\n";
rd.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
} else if (MCity[i].GetRedWushi() == NULL && MCity[i].GetBlueWushi() != NULL) {
cout << setfill('0') << setw(3) << Now << ":30 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter\n";
bl.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
}
}
}
/*
arrow有一个攻击力值R。如果下一步要走到的城市有敌人,那么拥有arrow的武士就会放箭攻击下一个城市的敌人(不能攻击对方司令部里的敌人)而不被还击
arrow使敌人的生命值减少R,若减至小于等于0,则敌人被杀死。arrow使用3次后即被耗尽,武士失去arrow。两个相邻的武士可能同时放箭把对方射死。
*/
int ArrowPowerR;
void Use_arrow() {
//000:35 blue dragon 1 shot
//cout<<"s shot...........\n";
for (int i = 0; i <= CntCity+1; i++) {
if (i < CntCity && MCity[i].GetRedWushi() != NULL && MCity[i+1].GetBlueWushi() != NULL)
if (MCity[i].GetRedWushi()->GetWuqiCas() & (1<<ARROW)) {
cout << setfill('0') << setw(3) << Now << ":35 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " shot";
//000:35 blue dragon 1 shot and killed red lion 4
//MCity[i+1].GetBlueWushi()->Hurted();
MCity[i+1].GetBlueWushi()->Add_Life(-ArrowPowerR);
if (MCity[i+1].GetBlueWushi()->Is_alive() == false) {
cout << " and killed blue " << SWushi[MCity[i+1].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i+1].GetBlueWushi()->GetId();
MCity[i+1].Arrow_Winner = RED_FLAG;
}
cout << endl;
MCity[i].GetRedWushi()->UseArrow();
}
if (i > 1 && MCity[i].GetBlueWushi() != NULL && MCity[i-1].GetRedWushi() != NULL)
if (MCity[i].GetBlueWushi()->GetWuqiCas() & (1<<ARROW)) {
cout << setfill('0') << setw(3) << Now << ":35 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " shot";
//000:35 blue dragon 1 shot and killed red lion 4
MCity[i-1].GetRedWushi()->Add_Life(-ArrowPowerR);
if (MCity[i-1].GetRedWushi()->Is_alive() == false) {
cout << " and killed red " << SWushi[MCity[i-1].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i-1].GetRedWushi()->GetId();
MCity[i-1].Arrow_Winner = BLUE_FLAG;
}
cout << endl;
MCity[i].GetBlueWushi()->UseArrow();
}
}
//cout<<"..............show out\n";
/* for (int i = 0; i <= CntCity+1; i++) {
if (MCity[i].GetRedWushi() != NULL) {
if (MCity[i].GetRedWushi()->Is_alive() == false)
MCity[i].SetRedWushi(NULL);
}
if (MCity[i].GetBlueWushi() != NULL) {
if (MCity[i].GetBlueWushi()->Is_alive() == false)
MCity[i].SetBlueWushi(NULL);
}
}*/
}
bool TestDie(Wushi *Bomber,Wushi *Enemy,bool IsFrist) {
if (IsFrist) {
return Enemy->GetLife() > Bomber->GetPower()
&& Enemy->GetrePower() >= Bomber->GetLife();
} else {
return Enemy->GetPower() >= Bomber->GetLife();
}
}
void Use_bomb() {
for (int i = 1; i <= CntCity; i++) {
if (MCity[i].Arrow_Winner != NO_FLAG) continue;
if (MCity[i].GetRedWushi() != NULL && MCity[i].GetBlueWushi()!=NULL) {
bool RedFirst = (MCity[i].flag == RED_FLAG || (MCity[i].flag == NO_FLAG && (i&1)));
if (MCity[i].GetRedWushi()->GetWuqiCas() & (1<<BOMB)) {
if (TestDie(MCity[i].GetRedWushi(),MCity[i].GetBlueWushi(),RedFirst)) {
//000:38 blue dragon 1 used a bomb and killed red lion 7
cout << setfill('0') << setw(3) << Now << ":38 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " used a bomb and killed blue " \
<< SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " << MCity[i].GetBlueWushi()->GetId() << endl;
MCity[i].SetRedWushi(NULL);
MCity[i].SetBlueWushi(NULL);
}
}
if (MCity[i].GetBlueWushi() != NULL)
if (MCity[i].GetBlueWushi()->GetWuqiCas() & (1<<BOMB)) {
if (TestDie(MCity[i].GetBlueWushi(),MCity[i].GetRedWushi(),!RedFirst)) {
//000:38 blue dragon 1 used a bomb and killed red lion 7
cout << setfill('0') << setw(3) << Now << ":38 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " used a bomb and killed red " \
<< SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " << MCity[i].GetRedWushi()->GetId() << endl;
MCity[i].SetRedWushi(NULL);
MCity[i].SetBlueWushi(NULL);
}
}
}
}
}
void Battle(Head &rd,Head &bl) {
vector<int> RedWinner;
vector<int> BlueWinner;
int rdlife = rd.GetLastLife(),bllife = bl.GetLastLife();
for (int i = 1; i <= CntCity; i++)
if(MCity[i].Arrow_Winner == RED_FLAG) {
MCity[i].Arrow_Winner = NO_FLAG;
if (MCity[i].GetRedWushi() == NULL) {
MCity[i].SetBlueWushi(NULL);
continue;
}
if (MCity[i].GetRedWushi()->Is_alive()==0) {
MCity[i].SetBlueWushi(NULL);
MCity[i].SetRedWushi(NULL);
continue;
}
if (MCity[i].GetRedWushi()->GetCasFlag() == CasDragon && \
(MCity[i].flag == RED_FLAG || (MCity[i].flag == NO_FLAG && (i&1))))
MCity[i].GetRedWushi()->YELL();
if (MCity[i].GetRedWushi()->GetCasFlag() == CasWolf) {
// cout<<"gdrgrdg";
MCity[i].GetRedWushi()->GetEnemyWuqi(MCity[i].GetBlueWushi());
}
cout << setfill('0') << setw(3) << Now << ":40 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
rd.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
RedWinner.push_back(i);
if (MCity[i].LastWinner != RED_FLAG)
MCity[i].LastWinner = RED_FLAG;
else if(MCity[i].flag != RED_FLAG) {
MCity[i].flag = RED_FLAG;
cout << setfill('0') << setw(3) << Now << ":40 " << "red flag raised in city " << i << endl;
}
MCity[i].SetBlueWushi(NULL);
} else if (MCity[i].Arrow_Winner == BLUE_FLAG) {
MCity[i].Arrow_Winner = NO_FLAG;
if (MCity[i].GetBlueWushi() == NULL) {
MCity[i].SetRedWushi(NULL);
continue;
}
if (MCity[i].GetBlueWushi()->Is_alive()==0) {
MCity[i].SetBlueWushi(NULL);
MCity[i].SetRedWushi(NULL);
continue;
}
if (MCity[i].GetBlueWushi()->GetCasFlag() == CasDragon && \
(MCity[i].flag == BLUE_FLAG || (MCity[i].flag == NO_FLAG && ((i&1)==0))))
MCity[i].GetBlueWushi()->YELL();
if (MCity[i].GetBlueWushi()->GetCasFlag() == CasWolf)
MCity[i].GetBlueWushi()->GetEnemyWuqi(MCity[i].GetRedWushi());
cout << setfill('0') << setw(3) << Now << ":40 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
bl.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
BlueWinner.push_back(i);
if (MCity[i].LastWinner != BLUE_FLAG)
MCity[i].LastWinner = BLUE_FLAG;
else if(MCity[i].flag != BLUE_FLAG) {
MCity[i].flag = BLUE_FLAG;
cout << setfill('0') << setw(3) << Now << ":40 " << "blue flag raised in city " << i << endl;
}
MCity[i].SetRedWushi(NULL);
} else if (MCity[i].GetRedWushi() != NULL && MCity[i].GetBlueWushi()!=NULL) {
if (MCity[i].flag == RED_FLAG || (MCity[i].flag == NO_FLAG && (i&1))) {
int IsWin = MCity[i].GetRedWushi()->Attact(MCity[i].GetBlueWushi());
//001:40 blue dragon 2 earned 10 elements for his headquarter
if (IsWin == 1) {
cout << setfill('0') << setw(3) << Now << ":40 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
rd.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
MCity[i].SetBlueWushi(NULL);
RedWinner.push_back(i);
if (MCity[i].LastWinner != RED_FLAG)
MCity[i].LastWinner = RED_FLAG;
else if(MCity[i].flag != RED_FLAG) {
MCity[i].flag = RED_FLAG;
// 004:40 blue flag raised in city 4
cout << setfill('0') << setw(3) << Now << ":40 " << "red flag raised in city " << i << endl;
}
} else {
if (IsWin == -1) {
// MCity[i].LastWinner = BLUE_FLAG;
cout << setfill('0') << setw(3) << Now << ":40 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
bl.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
MCity[i].SetRedWushi(NULL);
BlueWinner.push_back(i);
if (MCity[i].LastWinner != BLUE_FLAG)
MCity[i].LastWinner = BLUE_FLAG;
else if(MCity[i].flag != BLUE_FLAG) {
MCity[i].flag = BLUE_FLAG;
// 004:40 blue flag raised in city 4
cout << setfill('0') << setw(3) << Now << ":40 " << "blue flag raised in city " << i << endl;
}
}
else if (IsWin == 0)
MCity[i].LastWinner = NO_FLAG;
}
} else {
int IsWin = MCity[i].GetBlueWushi()->Attact(MCity[i].GetRedWushi());
if (IsWin == 1) {
cout << setfill('0') << setw(3) << Now << ":40 blue " << SWushi[MCity[i].GetBlueWushi()->GetCasFlag()] << " " \
<< MCity[i].GetBlueWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
bl.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
MCity[i].SetRedWushi(NULL);
BlueWinner.push_back(i);
if (MCity[i].LastWinner != BLUE_FLAG)
MCity[i].LastWinner = BLUE_FLAG;
else if(MCity[i].flag != BLUE_FLAG) {
MCity[i].flag = BLUE_FLAG;
// 004:40 blue flag raised in city 4
cout << setfill('0') << setw(3) << Now << ":40 " << "blue flag raised in city " << i << endl;
}
} else {
if (IsWin == -1) {
cout << setfill('0') << setw(3) << Now << ":40 red " << SWushi[MCity[i].GetRedWushi()->GetCasFlag()] << " " \
<< MCity[i].GetRedWushi()->GetId() << " earned " << MCity[i].MClife << " elements for his headquarter" << endl;
rd.AddLife(MCity[i].MClife);
MCity[i].MClife = 0;
MCity[i].SetBlueWushi(NULL);
RedWinner.push_back(i);
if (MCity[i].LastWinner != RED_FLAG)
MCity[i].LastWinner = RED_FLAG;
else if(MCity[i].flag != RED_FLAG) {
MCity[i].flag = RED_FLAG;
// 004:40 blue flag raised in city 4
cout << setfill('0') << setw(3) << Now << ":40 " << "red flag raised in city " << i << endl;
}
}
else if (IsWin == 0)
MCity[i].LastWinner = NO_FLAG;
}
}
//if(i==4)cout << MCity[i].GetRedWushi()->GetLife() << " " << MCity[i].GetRedWushi()->GetSelfPower()<<" kkkkk ";
}
//cerr<<"hrerhrggher\n";
for (int i = 0; i < BlueWinner.size(); i++) {
if (bllife < 8) break;
int tp = BlueWinner[i];
//cerr<<tp<<(MCity[i].GetBlueWushi()==NULL)<<" tp \n";
MCity[tp].GetBlueWushi()->Add_Life(8);
//cerr<<"ok";
bllife -= 8;
bl.AddLife(-8);
}
for (int i = RedWinner.size()-1; i >= 0; i--) {
if (rdlife < 8) break;
int tp = RedWinner[i];
//cerr<<tp<<"\n";
MCity[tp].GetRedWushi()->Add_Life(8);
rdlife -= 8;
rd.AddLife(-8);
}
//cout << "\ndfss\n";
}
void Head_report(Head &rd,Head &bl) {
//000:50 100 elements in red headquarter
cout << setfill('0') << setw(3) << Now << ":50 " << rd.GetLastLife() << " elements in red headquarter\n";
//000:50 120 elements in blue headquarter
cout << setfill('0') << setw(3) << Now << ":50 " << bl.GetLastLife() << " elements in blue headquarter\n";
}
void Wushi_report() {
for (int i = 0; i <= CntCity+1; i++)
if (MCity[i].RedWushi != NULL) {
// cout << i << " "<<"\n";
MCity[i].RedWushi->show_wuqi();
}
for (int i = 0; i <= CntCity+1; i++)
if (MCity[i].BlueWushi != NULL) {
// cout << i << " "<<"\n";
MCity[i].BlueWushi->show_wuqi();
}
}
int MAX_NOW,MAX_M;
bool Process(Head &rd,Head &bl) {
//武士降生
//cerr<<Now<<" ";
bool end = false;
if (Now == MAX_NOW)
end = true;
rd.Made();
bl.Made();// 00
if (end && MAX_M < 5) return false;
//lion逃跑
RunAway(); //05
if (end && MAX_M < 10) return false;
//武士前进到某一城市
for (int i = 1; i <= CntCity; i++)
MCity[i].Add_Life(10);
//cerr<<"a\n";
Marched(rd,bl); //10
// cerr<<"c"<<Winner;
if (Winner != NO_FLAG)
return false;
// cerr<<"ff"<<Winner;
if (end && MAX_M < 30) return false;
GetCityLife(rd,bl);//30
if (end && MAX_M < 35) return false;
Use_arrow();//35
if (end && MAX_M < 38) return false;
Use_bomb();//38
if (end && MAX_M < 40) return false;
//cout<<"hredherdh\n\n";
Battle(rd,bl);//40
//cerr<<"b\n";
if (end && MAX_M < 50) return false;
Head_report(rd,bl);//50
if (end && MAX_M < 55) return false;
Wushi_report();//55
//cerr << Now << " ddddd" << MAX_NOW << "\n\n";
// exit(0);
// cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\n";
Now++;
return true;
}
int main() {
// freopen("C:\\Users\\luhongxu\\Documents\\Qt work\\coursea\\a.in","r",stdin);
// freopen("C:\\Users\\luhongxu\\Documents\\Qt work\\coursea\\b.out","w",stdout);
int Cas;
cin >> Cas;
for (int i = 1; i <= Cas; i++) {
cout << "Case " << i << ":\n";
int M,N,R,K,T;
cin >> M >> N >> R >> K >> T;
Now = 0;
ArrowPowerR = R;
Lion_K = K;
MAX_NOW = T / 60;
MAX_M = T % 60;
Winner = NO_FLAG;
Init_City(N);
Head::init();
Head rd(M,true,2,3,4,1,0);
Head bl(M,false,3,0,1,2,4);
// while(1)
while(Process(rd,bl));
}
return 0;
}
来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩。)
注意: 总时间限制: 2000ms 内存限制: 65536kB
描述
魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 )。红魔军的司令部算作编号为0的城市,蓝魔军的司令部算作编号为N+1的城市。司令部有生命元,用于制造武士。
两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。
双方的武士编号都是从1开始计算。红方制造出来的第 n 个武士,编号就是n。同样,蓝方制造出来的第 n 个武士,编号也是n。
武士在刚降生的时候有一个初始的生命值,生命值在战斗中会发生变化,如果生命值减少到0(生命值变为负数时应当做变为0处理),则武士死亡(消失)。
有的武士可以拥有武器。武器有三种,sword, bomb,和arrow,编号分别为0,1,2。
武士降生后就朝对方司令部走,在经过的城市如果遇到敌人(同一时刻每个城市最多只可能有1个蓝武士和一个红武士),就会发生战斗。每次战斗只有一方发起主动进攻一次。被攻击者生命值会减去进攻者的攻击力值和进攻者手中sword的攻击力值。被进攻者若没死,就会发起反击,被反击者的生命值要减去反击者攻击力值的一半(去尾取整)和反击者手中sword的攻击力值。反击可能致敌人于死地。
如果武士在战斗中杀死敌人(不论是主动进攻杀死还是反击杀死),则其司令部会立即向其发送8个生命元作为奖励,使其生命值增加8。当然前提是司令部得有8个生命元。如果司令部的生命元不足以奖励所有的武士,则优先奖励距离敌方司令部近的武士。
如果某武士在某城市的战斗中杀死了敌人,则该武士的司令部立即取得该城市中所有的生命元。注意,司令部总是先完成全部奖励工作,然后才开始从各个打了胜仗的城市回收生命元。对于因司令部生命元不足而领不到奖励的武士,司令部也不会在取得战利品生命元后为其补发奖励。
如果一次战斗的结果是双方都幸存(平局),则双方都不能拿走发生战斗的城市的生命元。
城市可以插旗子,一开始所有城市都没有旗子。在插红旗的城市,以及编号为奇数的无旗城市,由红武士主动发起进攻。在插蓝旗的城市,以及编号为偶数的无旗城市,由蓝武士主动发起进攻。
当某个城市有连续两场战斗都是同一方的武士杀死敌人(两场战斗之间如果有若干个战斗时刻并没有发生战斗,则这两场战斗仍然算是连续的;但如果中间有平局的战斗,就不算连续了) ,那么该城市就会插上胜方的旗帜,若原来插着败方的旗帜,则败方旗帜落下。旗帜一旦插上,就一直插着,直到被敌人更换。一个城市最多只能插一面旗帜,旗帜没被敌人更换前,也不会再次插同颜色的旗。
各种武器有其特点:
sword武器的初始攻击力为拥有它的武士的攻击力的20%(去尾取整)。但是sword每经过一次战斗(不论是主动攻击还是反击),就会变钝,攻击力变为本次战斗前的80% (去尾取整)。sword攻击力变为0时,视为武士失去了sword。如果武士降生时得到了一个初始攻击力为0的sword,则视为武士没有sword.
arrow有一个攻击力值R。如果下一步要走到的城市有敌人,那么拥有arrow的武士就会放箭攻击下一个城市的敌人(不能攻击对方司令部里的敌人)而不被还击。arrow使敌人的生命值减少R,若减至小于等于0,则敌人被杀死。arrow使用3次后即被耗尽,武士失去arrow。两个相邻的武士可能同时放箭把对方射死。
拥有bomb的武士,在战斗开始前如果判断自己将被杀死(不论主动攻击敌人,或者被敌人主动攻击都可能导致自己被杀死,而且假设武士可以知道敌人的攻击力和生命值),那么就会使用bomb和敌人同归于尽。武士不预测对方是否会使用bomb。
武士使用bomb和敌人同归于尽的情况下,不算是一场战斗,双方都不能拿走城市的生命元,也不影响城市的旗帜。
不同的武士有不同的特点。
dragon可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。dragon 在一次在它主动进攻的战斗结束后,如果还没有战死,而且士气值大于0.8,就会欢呼。dragon每取得一次战斗的胜利(敌人被杀死),士气就会增加0.2,每经历一次未能获胜的战斗,士气值就会减少0.2。士气增减发生在欢呼之前。
ninjia可以拥有两件武器。编号为n的ninjia降生时即获得编号为 n%3 和 (n+1)%3的武器。ninja 挨打了也从不反击敌人。
iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。iceman 每前进两步,在第2步完成的时候,生命值会减少9,攻击力会增加20。但是若生命值减9后会小于等于0,则生命值不减9,而是变为1。即iceman不会因走多了而死。
lion 有“忠诚度”这个属性,其初始值等于它降生之后其司令部剩余生命元的数目。每经过一场未能杀死敌人的战斗,忠诚度就降低K。忠诚度降至0或0以下,则该lion逃离战场,永远消失。但是已经到达敌人司令部的lion不会逃跑。Lion在己方司令部可能逃跑。lion 若是战死,则其战斗前的生命值就会转移到对手身上。所谓“战斗前”,就是每个小时的40分前的一瞬间。
wolf降生时没有武器,但是在战斗中如果获胜(杀死敌人),就会缴获敌人的武器,但自己已有的武器就不缴获了。被缴获的武器当然不能算新的,已经被用到什么样了,就是什么样的。
以下是不同时间会发生的不同事件:
在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。
红方司令部按照 iceman、lion、wolf、ninja、dragon 的顺序制造武士。
蓝方司令部按照 lion、dragon、ninja、iceman、wolf 的顺序制造武士。
制造武士需要生命元。
制造一个初始生命值为 m 的武士,司令部中的生命元就要减少 m 个。
如果司令部中的生命元不足以制造某武士,那么司令部就等待,直到获得足够生命元后的第一个整点,才制造该武士。例如,在2:00,红方司令部本该制造一个 wolf ,如果此时生命元不足,那么就会等待,直到生命元足够后的下一个整点,才制造一个 wolf。
在每个小时的第5分,该逃跑的lion就在这一时刻逃跑了。
在每个小时的第10分:所有的武士朝敌人司令部方向前进一步。即从己方司令部走到相邻城市,或从一个城市走到下一个城市。或从和敌军司令部相邻的城市到达敌军司令部。
在每个小时的第20分:每个城市产出10个生命元。生命元留在城市,直到被武士取走。
在每个小时的第30分:如果某个城市中只有一个武士,那么该武士取走该城市中的所有生命元,并立即将这些生命元传送到其所属的司令部。
在每个小时的第35分,拥有arrow的武士放箭,对敌人造成伤害。放箭事件应算发生在箭发出的城市。注意,放箭不算是战斗,因此放箭的武士不会得到任何好处。武士在没有敌人的城市被箭射死也不影响其所在城市的旗帜更换情况。
在每个小时的第38分,拥有bomb的武士评估是否应该使用bomb。如果是,就用bomb和敌人同归于尽。
在每个小时的第40分:在有两个武士的城市,会发生战斗。 如果敌人在5分钟前已经被飞来的arrow射死,那么仍然视为发生了一场战斗,而且存活者视为获得了战斗的胜利。此情况下不会有“武士主动攻击”,“武士反击”,“武士战死”的事件发生,但战斗胜利后应该发生的事情都会发生。如Wolf一样能缴获武器,旗帜也可能更换,等等。在此情况下,Dragon同样会通过判断是否应该轮到自己主动攻击来决定是否欢呼。
在每个小时的第50分,司令部报告它拥有的生命元数量。
在每个小时的第55分,每个武士报告其拥有的武器情况。
武士到达对方司令部后就算完成任务了,从此就呆在那里无所事事。
任何一方的司令部里若是出现了2个敌人,则认为该司令部已被敌人占领。
任何一方的司令部被敌人占领,则战争结束。战争结束之后就不会发生任何事情了。
给定一个时间,要求你将从0点0分开始到此时间为止的所有事件按顺序输出。事件及其对应的输出样例如下:
1) 武士降生
输出样例: 000:00 blue lion 1 born
表示在 0点0分,编号为1的蓝魔lion武士降生
如果造出的是dragon,那么还要多输出一行,例:
000:00 blue dragon 1 born
Its morale is 23.34
表示该该dragon降生时士气是23. 34(四舍五入到小数点后两位)
如果造出的是lion,那么还要多输出一行,例:
000:00 blue lion 1 born
Its loyalty is 24
表示该lion降生时的忠诚度是24
2) lion逃跑
输出样例: 000:05 blue lion 1 ran away
表示在 0点5分,编号为1的蓝魔lion武士逃走
3) 武士前进到某一城市
输出样例: 000:10 red iceman 1 marched to city 1 with 20 elements and force 30
表示在 0点10分,红魔1号武士iceman前进到1号城市,此时他生命值为20,攻击力为30
对于iceman,输出的生命值和攻击力应该是变化后的数值
4)武士放箭
输出样例: 000:35 blue dragon 1 shot
表示在 0点35分,编号为1的蓝魔dragon武士射出一支箭。如果射出的箭杀死了敌人,则应如下输出:
000:35 blue dragon 1 shot and killed red lion 4
表示在 0点35分,编号为1的蓝魔dragon武士射出一支箭,杀死了编号为4的红魔lion。
5)武士使用bomb
输出样例: 000:38 blue dragon 1 used a bomb and killed red lion 7
表示在 0点38分,编号为1的蓝魔dragon武士用炸弹和编号为7的红魔lion同归于尽。
6) 武士主动进攻
输出样例:000:40 red iceman 1 attacked blue lion 1 in city 1 with 20 elements and force 30
表示在0点40分,1号城市中,红魔1号武士iceman 进攻蓝魔1号武士lion,在发起进攻前,红魔1号武士iceman生命值为20,攻击力为 30
7) 武士反击
输出样例:001:40 blue dragon 2 fought back against red lion 2 in city 1
表示在1点40分,1号城市中,蓝魔2号武士dragon反击红魔2号武士lion
8) 武士战死
输出样例:001:40 red lion 2 was killed in city 1
被箭射死的武士就不会有这一条输出。
9) 武士欢呼
输出样例:003:40 blue dragon 2 yelled in city 4
10) 武士获取生命元( elements )
输出样例:001:40 blue dragon 2 earned 10 elements for his headquarter
11) 旗帜升起
输出样例:004:40 blue flag raised in city 4
12) 武士抵达敌军司令部
输出样例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
(此时他生命值为20,攻击力为30)对于iceman,输出的生命值和攻击力应该是变化后的数值
13) 司令部被占领
输出样例:003:10 blue headquarter was taken
14)司令部报告生命元数量
000:50 100 elements in red headquarter
000:50 120 elements in blue headquarter
表示在0点50分,红方司令部有100个生命元,蓝方有120个
15)武士报告武器情况
000:55 blue wolf 2 has arrow(2),bomb,sword(23)
000:55 blue wolf 4 has no weapon
000:55 blue wolf 5 has sword(20)
表示在0点55分,蓝魔2号武士wolf有一支arrow(这支arrow还可以用2次),一个bomb,还有一支攻击力为23的sword。
蓝魔4号武士wolf没武器。
蓝魔5号武士wolf有一支攻击力为20的sword。
交代武器情况时,次序依次是:arrow,bomb,sword。如果没有某种武器,某种武器就不用提。报告时,先按从西向东的顺序所有的红武士报告,然后再从西向东所有的蓝武士报告。
输出事件时:
首先按时间顺序输出;
同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地。
在一次战斗中有可能发生上面的 6 至 11 号事件。这些事件都算同时发生,其时间就是战斗开始时间。一次战斗中的这些事件,序号小的应该先输出。
两个武士同时抵达同一城市,则先输出红武士的前进事件,后输出蓝武士的。
显然,13号事件发生之前的一瞬间一定发生了12号事件。输出时,这两件事算同一时间发生,但是应先输出12号事件
虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。
输入
第一行是t,代表测试数据组数
每组样例共三行。
第一行,五个整数 M,N,R,K, T。其含义为:
每个司令部一开始都有M个生命元( 1 <= M <= 10000)
两个司令部之间一共有N个城市( 1 <= N <= 20 )
arrow的攻击力是R
lion每经过一场未能杀死敌人的战斗,忠诚度就降低K。
要求输出从0时0分开始,到时间T为止(包括T) 的所有事件。T以分钟为单位,0 <= T <= 5000
第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于10000
第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于10000
输出
对每组数据,先输出一行:
Case n:
如对第一组数据就输出 Case1:
然后按恰当的顺序和格式输出到时间T为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是“时: 分”,“时”有三位,“分”有两位。
样例输入
1
2
3
4
1
20 1 10 10 1000
20 20 30 10 20
5 5 5 5 5
样例输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Case 1:
000:00 blue lion 1 born
Its loyalty is 10
000:10 blue lion 1 marched to city 1 with 10 elements and force 5
000:30 blue lion 1 earned 10 elements for his headquarter
000:50 20 elements in red headquarter
000:50 20 elements in blue headquarter
000:55 blue lion 1 has no weapon
001:00 blue dragon 2 born
Its morale is 0.00001:10 blue lion 1 reached red headquarter with 10 elements and force 5
001:10 blue dragon 2 marched to city 1 with 20 elements and force 5
001:30 blue dragon 2 earned 10 elements for his headquarter
001:50 20 elements in red headquarter
001:50 10 elements in blue headquarter
001:55 blue lion 1 has no weapon
001:55 blue dragon 2 has arrow(3)
002:10 blue dragon 2 reached red headquarter with 20 elements and force 5
002:10 red headquarter was taken