魔兽世界之三:开战

题目:

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为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。

sword的攻击力是使用者当前攻击力的20%(去尾取整)。

bomb的攻击力是使用者当前攻击力的40%(去尾取整),但是也会导致使用者受到攻击,对使用者的攻击力是对敌人取整后的攻击力的1/2(去尾取整)。Bomb一旦使用就没了。

arrow的攻击力是使用者当前攻击力的30%(去尾取整)。一个arrow用两次就没了。

武士降生后就朝对方司令部走,在经过的城市如果遇到敌人(同一时刻每个城市最多只可能有1个蓝武士和一个红武士),就会发生战斗。战斗的规则是:

  1. 在奇数编号城市,红武士先发起攻击

  2. 在偶数编号城市,蓝武士先发起攻击

  3. 战斗开始前,双方先对自己的武器排好使用顺序,然后再一件一件地按顺序使用。编号小的武器,排在前面。若有多支arrow,用过的排在前面。排好序后,攻击者按此排序依次对敌人一件一件地使用武器。如果一种武器有多件,那就都要用上。每使用一件武器,被攻击者生命值要减去武器攻击力。如果任何一方生命值减为0或小于0即为死去。有一方死去,则战斗结束。

  4. 双方轮流使用武器,甲用过一件,就轮到乙用。某一方把自己所有的武器都用过一轮后,就从头开始再用一轮。如果某一方没有武器了,那就挨打直到死去或敌人武器用完。武器排序只在战斗前进行,战斗中不会重新排序。

  5. 如果双方武器都用完且都还活着,则战斗以平局结束。如果双方都死了,也算平局。

  6. 有可能由于武士自身攻击力太低,而导致武器攻击力为0。攻击力为0的武器也要使用。如果战斗中双方的生命值和武器的状态都不再发生变化,则战斗结束,算平局。

  7. 战斗的胜方获得对方手里的武器。武士手里武器总数不超过10件。缴获武器时,按照武器种类编号从小到大缴获。如果有多件arrow,优先缴获没用过的。

  8. 如果战斗开始前双方都没有武器,则战斗视为平局。如果先攻击方没有武器,则由后攻击方攻击。

不同的武士有不同的特点。

编号为n的dragon降生时即获得编号为n%3 的武器。dragon在战斗结束后,如果还没有战死,就会欢呼。

编号为n的ninjia降生时即获得编号为n%3 和(n+1)%3的武器。ninja 使用bomb不会让自己受伤。

编号为n的iceman降生时即获得编号为n%3 的武器。iceman每前进一步,生命值减少10%(减少的量要去尾取整)。

编号为n的lion降生时即获得编号为n%3 的武器。lion 有“忠诚度”这个属性,其初始值等于它降生之后其司令部剩余生命元的数目。每前进一步忠诚度就降低K。忠诚度降至0或0以下,则该lion逃离战场,永远消失。但是已经到达敌人司令部的lion不会逃跑。lion在己方司令部可能逃跑。

wolf降生时没有武器,但是在战斗开始前会抢到敌人编号最小的那种武器。如果敌人有多件这样的武器,则全部抢来。Wolf手里武器也不能超过10件。如果敌人arrow太多没法都抢来,那就先抢没用过的。如果敌人也是wolf,则不抢武器。

以下是不同时间会发生的不同事件:

在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。

红方司令部按照iceman、lion、wolf、ninja、dragon 的顺序制造武士。

蓝方司令部按照lion、dragon、ninja、iceman、wolf 的顺序制造武士。

制造武士需要生命元。

制造一个初始生命值为m 的武士,司令部中的生命元就要减少m 个。

如果司令部中的生命元不足以制造某本该造的武士,那就从此停止制造武士。

在每个小时的第5分,该逃跑的lion就在这一时刻逃跑了。

在每个小时的第10分:所有的武士朝敌人司令部方向前进一步。即从己方司令部走到相邻城市,或从一个城市走到下一个城市。或从和敌军司令部相邻的城市到达敌军司令部。

在每个小时的第35分:在有wolf及其敌人的城市,wolf要抢夺对方的武器。

在每个小时的第40分:在有两个武士的城市,会发生战斗。

在每个小时的第50分,司令部报告它拥有的生命元数量。

在每个小时的第55分,每个武士报告其拥有的武器情况。

武士到达对方司令部后就算完成任务了,从此就呆在那里无所事事。

任何一方的司令部里若是出现了敌人,则认为该司令部已被敌人占领。

任何一方的司令部被敌人占领,则战争结束。战争结束之后就不会发生任何事情了。

给定一个时间,要求你将从0点0分开始到此时间为止的所有事件按顺序输出。事件及其对应的输出样例如下:

1) 武士降生

输出样例:000:00 blue dragon 1 born

表示在0点0分,编号为1的蓝魔dragon武士降生

如果造出的是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) wolf抢敌人的武器

000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4

表示在0点35分,4号城市中,红魔1号武士wolf 抢走蓝魔2号武士dragon 3个bomb。为简单起见,武器不写复数形式

5) 报告战斗情况

战斗只有3种可能的输出结果:

000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements

表示在0点40分,1号城市中,红魔1号武士iceman 杀死蓝魔12号武士lion后,剩下生命值20

000:40 both red iceman 1 and blue lion 12 died in city 2

注意,把红武士写前面

000:40 both red iceman 1 and blue lion 12 were alive in city 2

注意,把红武士写前面

6) 武士欢呼

输出样例:003:40 blue dragon 2 yelled in city 4

7) 武士抵达敌军司令部

输出样例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30

(此时他生命值为20,攻击力为30)对于iceman,输出的生命值和攻击力应该是变化后的数值

8) 司令部被占领

输出样例:003:10 blue headquarter was taken

9)司令部报告生命元数量

000:50 100 elements in red headquarter

000:50 120 elements in blue headquarter

表示在0点50分,红方司令部有100个生命元,蓝方有120个

10)武士报告情况

000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements

为简单起见,武器都不写复数形式。elements一律写复数,哪怕只有1个

交代武器情况时,次序依次是:sword,bomb, arrow。

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地。

在一次战斗中有可能发生上面的 5 至 6 号事件。这些事件都算同时发生,其时间就是战斗开始时间。一次战斗中的这些事件,序号小的应该先输出。

两个武士同时抵达同一城市,则先输出红武士的前进事件,后输出蓝武士的。

对于同一城市,同一时间发生的事情,先输出红方的,后输出蓝方的。

显然,8号事件发生之前的一瞬间一定发生了7号事件。输出时,这两件事算同一时间发生,但是应先输出7号事件

虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。


输入 第一行是t,代表测试数据组数

每组样例共三行。

第一行,4个整数 M,N,K, T。其含义为:
每个司令部一开始都有M个生命元( 1 <= M <= 100000)
两个司令部之间一共有N个城市( 1 <= N <= 20 )
lion每前进一步,忠诚度就降低K。(0<=K<=100)
要求输出从0时0分开始,到时间T为止(包括T) 的所有事件。T以分钟为单位,0 <= T <= 6000

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于200

第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于200
输出 对每组数据,先输出一行:

Case n:

如对第一组数据就输出 Case 1:

然后按恰当的顺序和格式输出到时间T为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是“时: 分”,“时”有三位,“分”有两位。

分析: 基于魔兽2修改,重点在于编写前进、战斗两个部分。weaponList类存放武士的武器。定义城市结构体City数组,每个城市有两个warrior类指针和两个warrior类临时指针。武士前进即将上一个城市的指针赋值给目标城市的临时指针,自身变为NULL,从而按指定的顺序输出动作。全部移动后,所有临时指针归位。战斗部分即单次攻击的循环,注意细节。
代码:
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
using namespace std;

//attention to initialize data for every test data
const string weap[3] = {"sword", "bomb", "arrow"};
int blue_ord[5] = {4,1,2,3,5};  //blue headquarter order: lion,dragon,ninja,iceman,wolf
int red_ord[5] = {3,4,5,2,1};   //red headquarter order: iceman,lion,wolf,ninja,dragon
int ini_life[6];    //lif[1~5] refers to initial life of dragon 、ninja、iceman、lion、wolf
int AttackForce[6];   //AttackForce for dragon 、ninja、iceman、lion、wolf
int LoyaltyDecrease;   //loyalty decreasing every step for a lion
int Hour=0;
bool MainFlag=1;   //judge whether a headquarter is taken

//standard form of time output
void show_hour() {
	cout<<setw(3)<<setfill('0')<<Hour;
}

//weapons belong to a warrior
class weaponList {
	public:
		int SumWeap;
		int WeapNum[3];
		int UsedArrow;
		weaponList(): SumWeap(0), UsedArrow(0) {
			for (int i=0; i<3; ++i) WeapNum[i]=0;
		}
		weaponList(int n1): SumWeap(1), UsedArrow(0) {
			for (int i=0; i<3; ++i) WeapNum[i]=0;
			WeapNum[n1]++;
		}
		weaponList(int n1, int n2): SumWeap(2), UsedArrow(0) {
			for (int i=0; i<3; ++i) WeapNum[i]=0;
			WeapNum[n1]++;
			WeapNum[n2]++;
		}
		void weap_show () {
			cout<<WeapNum[0]<<"sword "<<WeapNum[1]<<"bomb "<<WeapNum[2]<<"arrow alltogether:"<<SumWeap<<endl;
		} //for debug
};

//warrior class
class warrior {
	public:
		string Name;
		string Head;
		int Number;
		int Life;
		int Attack;
		bool hasMoved; //should be initialized before every move action
		weaponList weapons;
		warrior(string s, string h, int n1, int n2, int n3): weapons(), Name(s), Head(h), Number(n1), Life(n2), Attack(n3), hasMoved(0) {}
		warrior(string s, string h, int n1, int n2, int n3, int n4_1): weapons(n4_1), Name(s), Head(h), Number(n1), Life(n2), Attack(n3) {}
		warrior(string s, string h, int n1, int n2, int n3, int n4_1, int n4_2): weapons(n4_1, n4_2), Name(s), Head(h), Number(n1), Life(n2), Attack(n3) {}
		// 3 different constructor for all kinds of warriors.
		//debug
		void showWarrior () {
			cout<<"Name:"<<Name<<" Head:"<<Head<<" Number:"<<Number<<" Life:"<<Life<<" Attack:"<<Attack<<endl;
			weapons.weap_show();
		} //for debug
		virtual bool LionEscape() {
			return 0;
		}
		virtual void LionMove() {}
};
class Dragon: public warrior {
	public:
		Dragon (string s, string h, int n1, int n2, int n3, int n4_1): warrior(s, h, n1, n2, n3, n4_1) {}
};
class Ninja: public warrior {
	public:
		Ninja (string s, string h, int n1, int n2, int n3, int n4_1, int n4_2): warrior(s, h, n1, n2, n3, n4_1, n4_2) {}
};
class Iceman: public warrior {
	public:
		Iceman (string s, string h, int n1, int n2, int n3, int n4_1): warrior(s, h, n1, n2, n3, n4_1) {}
};
class Lion: public warrior {
	public:
		int Loyalty;
		Lion(string s, string h, int n1, int n2, int n3, int n4_1, int n5): warrior(s, h, n1, n2, n3, n4_1), Loyalty(n5) {}
		bool LionEscape() {
			if (Loyalty>0) return 0;
			show_hour();
			cout<<":05 "<<Head<<" lion "<<Number<<" ran away"<<endl;
			//delete this;
			return 1;
		} //judge whether the lion escapes
		void LionMove() {
			Loyalty-=LoyaltyDecrease;
		}
};
class Wolf: public warrior {
	public:
		Wolf (string s, string h, int n1, int n2, int n3): warrior(s, h, n1, n2, n3) {}
};

//city
struct City {
	string CityName;
	warrior *redwarrior;
	warrior *bluewarrior;
	warrior *tempred;
	warrior *tempblue; //temporary pointer to warriors, remember to transform after move!
	bool isHead;
}; //attention to initialization!

//headquarter class
class Headquarter {
	public:
		string Hname;
		int lifeunit;
		int warrior_num;
		int scanner;
		int scan_order[5];
		bool pro_abl;  //judge whether this headquarter is able to produce warriors
		Headquarter(string s, int n1,  int *arr): Hname(s), lifeunit(n1), warrior_num(0), scanner(-1), pro_abl(1) {
			for (int i=0; i<5; ++i) scan_order[i]=arr[i];
		}
};


//headquarter produce a warrior
void producing (warrior* &pointer, Headquarter &headquarter) {
	if (!headquarter.pro_abl) {
		cout<<"Error!"<<endl;
		return;
	}
	headquarter.scanner++;
	if (headquarter.lifeunit<ini_life[headquarter.scan_order[headquarter.scanner%5]]) {
		headquarter.pro_abl=0;
		return;
	}
	int res=headquarter.scan_order[headquarter.scanner%5];
	++headquarter.warrior_num;
	headquarter.lifeunit-=ini_life[res];
	show_hour();
	cout<<":00 "<<headquarter.Hname<<' ';
	switch (res) {
		case 1: {
			pointer=new Dragon("dragon",headquarter.Hname,headquarter.warrior_num,ini_life[1],AttackForce[1],headquarter.warrior_num%3);
			cout<<"dragon ";
			cout<<headquarter.warrior_num<<" born"<<endl;
			break;
		}
		case 2: {
			pointer=new Ninja("ninja",headquarter.Hname,headquarter.warrior_num,ini_life[2],AttackForce[2],headquarter.warrior_num%3,(headquarter.warrior_num+1)%3);
			cout<<"ninja ";
			cout<<headquarter.warrior_num<<" born"<<endl;
			break;
		}
		case 3: {
			pointer=new Iceman("iceman",headquarter.Hname,headquarter.warrior_num,ini_life[3],AttackForce[3],headquarter.warrior_num%3);
			cout<<"iceman ";
			cout<<headquarter.warrior_num<<" born"<<endl;
			break;
		}
		case 4: {
			pointer=new Lion("lion",headquarter.Hname,headquarter.warrior_num,ini_life[4],AttackForce[4],headquarter.warrior_num%3,headquarter.lifeunit);
			cout<<"lion ";
			cout<<headquarter.warrior_num<<" born"<<endl;
			cout<<"Its loyalty is "<<headquarter.lifeunit<<endl;
			break;
		}
		case 5: {
			pointer=new Wolf("wolf",headquarter.Hname,headquarter.warrior_num,ini_life[5],AttackForce[5]);
			cout<<"wolf ";
			cout<<headquarter.warrior_num<<" born"<<endl;
			break;
		}
		default: {
			break;
		}
	}
}


//move function for a single destination .
void warriorMove (City* destination, City* leftCity, City* rightCity) {

	if (leftCity->redwarrior) {
		if (leftCity->redwarrior->Name=="iceman") leftCity->redwarrior->Life-=(leftCity->redwarrior->Life)/10;
		if (leftCity->redwarrior->Name=="lion") leftCity->redwarrior->LionMove();
		show_hour();
		if (!(destination->isHead)) {
			cout<<":10 "<<"red "<<leftCity->redwarrior->Name<<" "<<leftCity->redwarrior->Number<<" marched to city "
			    <<destination->CityName<<" with "<<leftCity->redwarrior->Life<<" elements and force "
			    <<leftCity->redwarrior->Attack<<endl;
		} else if (destination->isHead) {
			cout<<":10 "<<"red "<<leftCity->redwarrior->Name<<" "<<leftCity->redwarrior->Number<<" reached blue headquarter with "
			    <<leftCity->redwarrior->Life<<" elements and force "<<leftCity->redwarrior->Attack<<endl;
			show_hour();
			cout<<":10 blue headquarter was taken"<<endl;
			MainFlag=0;
		}
		destination->tempred = leftCity->redwarrior;
		leftCity->redwarrior=NULL;
	}


	if (rightCity->bluewarrior) {
		if (rightCity->bluewarrior->Name=="iceman") rightCity->bluewarrior->Life-=(rightCity->bluewarrior->Life)/10;
		if (rightCity->bluewarrior->Name=="lion") rightCity->bluewarrior->LionMove();
		show_hour();
		if (!(destination->isHead)) {
			cout<<":10 "<<"blue "<<rightCity->bluewarrior->Name<<" "<<rightCity->bluewarrior->Number<<" marched to city "
			    <<destination->CityName<<" with "<<rightCity->bluewarrior->Life<<" elements and force "
			    <<rightCity->bluewarrior->Attack<<endl;
		} else if(destination->isHead) {
			cout<<":10 "<<"blue "<<rightCity->bluewarrior->Name<<" "<<rightCity->bluewarrior->Number<<" reached red headquarter with "
			    <<rightCity->bluewarrior->Life<<" elements and force "<<rightCity->bluewarrior->Attack<<endl;
			show_hour();
			cout<<":10 red headquarter was taken"<<endl;
			MainFlag=0;
		}
		destination->tempblue = rightCity->bluewarrior;
		rightCity->bluewarrior=NULL;
	}

}

//all the warriors move in order
void allWarriorMove (City* cityArray, int start, int end) {
	for (int i=start; i<=end; ++i) warriorMove(&cityArray[i], &cityArray[i-1], &cityArray[i+1]);
}

//move warriors to correct place in a city
void warriorPlace (City* destination) {
	if (destination->tempblue) {
		destination->bluewarrior=destination->tempblue;
		destination->tempblue=NULL;
	}
	if (destination->tempred) {
		destination->redwarrior=destination->tempred;
		destination->tempred=NULL;
	}
}


//wolf rob other enimie
void rob (City* city) {
	if (city->redwarrior->Name!="wolf" && city->bluewarrior->Name!="wolf") return;
	if (city->redwarrior->Name=="wolf" && city->bluewarrior->Name=="wolf") return;
	if (city->redwarrior->Name=="wolf") {
		if (city->redwarrior->weapons.SumWeap==10 || city->bluewarrior->weapons.SumWeap==0) return;
		int i_=0;
		for (i_=0; i_<3; i_++) {
			if (city->bluewarrior->weapons.WeapNum[i_]>0) break;
		}
		int robNum = min (city->bluewarrior->weapons.WeapNum[i_], 10-city->redwarrior->weapons.SumWeap);
		if (i_==2) {
			if (city->bluewarrior->weapons.WeapNum[2] - city->bluewarrior->weapons.UsedArrow < robNum) {
				int used_change=city->bluewarrior->weapons.UsedArrow-city->bluewarrior->weapons.WeapNum[2]+robNum;
				city->bluewarrior->weapons.UsedArrow-=used_change;
				city->redwarrior->weapons.UsedArrow+=used_change;
			}
		}
		city->redwarrior->weapons.SumWeap+=robNum;
		city->redwarrior->weapons.WeapNum[i_]+=robNum;
		city->bluewarrior->weapons.WeapNum[i_]-=robNum;
		city->bluewarrior->weapons.SumWeap-=robNum;
		show_hour();
		cout<<":35 "<<"red wolf "<<city->redwarrior->Number<<" took "<<robNum<<" "<<weap[i_]<<" from blue "
		    <<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" in city "<<city->CityName<<endl;
	} else if (city->bluewarrior->Name=="wolf") {
		if (city->bluewarrior->weapons.SumWeap==10 || city->redwarrior->weapons.SumWeap==0) return;
		int i_=0;
		for (i_=0; i_<3; i_++) {
			if (city->redwarrior->weapons.WeapNum[i_]>0) break;
		}
		int robNum = min (city->redwarrior->weapons.WeapNum[i_], 10-city->bluewarrior->weapons.SumWeap);
		if (i_==2) {
			if (city->redwarrior->weapons.WeapNum[2] - city->redwarrior->weapons.UsedArrow < robNum) {
				int used_change=city->redwarrior->weapons.UsedArrow-city->redwarrior->weapons.WeapNum[2]+robNum;
				city->redwarrior->weapons.UsedArrow-=used_change;
				city->bluewarrior->weapons.UsedArrow+=used_change;
			}
		}
		city->bluewarrior->weapons.SumWeap+=robNum;
		city->bluewarrior->weapons.WeapNum[i_]+=robNum;
		city->redwarrior->weapons.WeapNum[i_]-=robNum;
		city->redwarrior->weapons.SumWeap-=robNum;
		show_hour();
		cout<<":35 "<<"blue wolf "<<city->bluewarrior->Number<<" took "<<robNum<<" "<<weap[i_]<<" from red "
		    <<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" in city "<<city->CityName<<endl;
	}
}


//one warrior attack another with a weapon
void OneTimeAttack (warrior* &attacker, warrior* &another, int weapon_) {
	switch(weapon_) {
		case 0: {
			another->Life-=(attacker->Attack)/5;
			break;
		}
		case 1: {
			another->Life-=(attacker->Attack)*2/5;
			if (attacker->Name!="ninja") attacker->Life-=(attacker->Attack)/5;
			attacker->weapons.SumWeap--;
			attacker->weapons.WeapNum[1]--;
			break;
		}
		case 2: {
			another->Life-=(attacker->Attack)*3/10;
			if (attacker->weapons.UsedArrow>0) {
				attacker->weapons.UsedArrow--;
				attacker->weapons.WeapNum[2]--;
				attacker->weapons.SumWeap--;
			} else {
				attacker->weapons.UsedArrow++;
			}
			break;
		}
	}
}

//capture after battle
void captureWeapon(warrior* &attacker, warrior* &another) {
	int addw0=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[0]);
	attacker->weapons.WeapNum[0]+=addw0;
	attacker->weapons.SumWeap+=addw0;
	int addw1=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[1]);
	attacker->weapons.WeapNum[1]+=addw1;
	attacker->weapons.SumWeap+=addw1;
	int addw2=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[2]);
	attacker->weapons.WeapNum[2]+=addw2;
	attacker->weapons.SumWeap+=addw2;
	if (addw2 > another->weapons.WeapNum[2]-another->weapons.UsedArrow)
		attacker->weapons.UsedArrow+=(addw2-another->weapons.WeapNum[2]+another->weapons.UsedArrow);
}

//judge an one-time-attacking result
bool attackResult(City* city) {
	if (city->redwarrior->Life<=0 && city->bluewarrior->Life<=0) {
		show_hour();
		cout<<":40 both red "<<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" and blue "
		    <<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" died in city "<<city->CityName<<endl;
		delete city->bluewarrior;
		city->bluewarrior=NULL;
		delete city->redwarrior;
		city->redwarrior=NULL;
		return 1;
	}
	if (city->bluewarrior->Life<=0) {
		captureWeapon(city->redwarrior, city->bluewarrior);
		show_hour();
		cout<<":40 red "<<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" killed blue "
		    <<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" in city "<<city->CityName
		    <<" remaining "<<city->redwarrior->Life<<" elements"<<endl;
		delete city->bluewarrior;
		city->bluewarrior=NULL;
		if(city->redwarrior->Name=="dragon") {
			show_hour();
			cout<<":40 "<<city->redwarrior->Head<<" dragon "<<city->redwarrior->Number<<" yelled in city "<<city->CityName<<endl;
		}
		return 1;
	}
	if (city->redwarrior->Life<=0) {
		captureWeapon(city->bluewarrior, city->redwarrior);
		show_hour();
		cout<<":40 blue "<<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" killed red "
		    <<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" in city "<<city->CityName
		    <<" remaining "<<city->bluewarrior->Life<<" elements"<<endl;
		delete city->redwarrior;
		city->redwarrior=NULL;
		if(city->bluewarrior->Name=="dragon") {
			show_hour();
			cout<<":40 "<<city->bluewarrior->Head<<" dragon "<<city->bluewarrior->Number<<" yelled in city "<<city->CityName<<endl;
		}
		return 1;
	}
	return 0;
}

//battle in a city
void Battling (City* city, int city_num) {
	if (!(city->redwarrior && city->bluewarrior)) return;
	bool temp_flag=0;
	int redlife=city->redwarrior->Life, redweap=city->redwarrior->weapons.SumWeap, reduarrow=city->redwarrior->weapons.UsedArrow,
	    bluelife=city->bluewarrior->Life, blueweap=city->bluewarrior->weapons.SumWeap, blueuarrow=city->bluewarrior->weapons.UsedArrow;  //for judging a tie
	int i_red=-1, i_blue=-1;    //weapon
	if (city_num%2==1) {
		if (city->redwarrior->weapons.SumWeap) {
			for (int i=1; i<=3; ++i) {
				i_red++;
				if (city->redwarrior->weapons.WeapNum[i_red%3]) break;
			}
			OneTimeAttack(city->redwarrior, city->bluewarrior, i_red%3);
			if (attackResult(city)) return;
		}
	}
	int tie_counter=0;
	while (!temp_flag) {
		redlife=city->redwarrior->Life;
		redweap=city->redwarrior->weapons.SumWeap;
		reduarrow=city->redwarrior->weapons.UsedArrow;
		bluelife=city->bluewarrior->Life;
		blueweap=city->bluewarrior->weapons.SumWeap;
		blueuarrow=city->bluewarrior->weapons.UsedArrow;
		if (city->bluewarrior->weapons.SumWeap) {
			for (int i=1; i<=3; ++i) {
				i_blue++;
				if (city->bluewarrior->weapons.WeapNum[i_blue%3]) break;
			}
			OneTimeAttack(city->bluewarrior,city->redwarrior,i_blue%3);
			if (attackResult(city)) return;
		}
		if (city->redwarrior->weapons.SumWeap) {
			for (int i=1; i<=3; ++i) {
				i_red++;
				if (city->redwarrior->weapons.WeapNum[i_red%3]) break;
			}
			OneTimeAttack(city->redwarrior, city->bluewarrior, i_red%3);
			if (attackResult(city)) return;
		}
		if (redlife==city->redwarrior->Life&& redweap==city->redwarrior->weapons.SumWeap&&reduarrow==city->redwarrior->weapons.UsedArrow&&
		        bluelife==city->bluewarrior->Life&& blueweap==city->bluewarrior->weapons.SumWeap&&blueuarrow==city->bluewarrior->weapons.UsedArrow) {
			tie_counter++;
		} else tie_counter=0;
		if (tie_counter>=3) {
			temp_flag=1;
			break;
		}
	}
	if (temp_flag) {
		show_hour();
		cout<<":40 both red "<<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" and blue "
		    <<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" were alive in city "<<city->CityName<<endl;
		if(city->redwarrior->Name=="dragon") {
			show_hour();
			cout<<":40 "<<city->redwarrior->Head<<" dragon "<<city->redwarrior->Number<<" yelled in city "<<city->CityName<<endl;
		}
		if(city->bluewarrior->Name=="dragon") {
			show_hour();
			cout<<":40 "<<city->bluewarrior->Head<<" dragon "<<city->bluewarrior->Number<<" yelled in city "<<city->CityName<<endl;
		}
	}
}


//headquarter announcement
void headAnnounce (Headquarter &red, Headquarter &blue) {
	show_hour();
	cout<<":50 "<<red.lifeunit<<" elements in red headquarter"<<endl;
	show_hour();
	cout<<":50 "<<blue.lifeunit<<" elements in blue headquarter"<<endl;
}

//warrior announcement
void warriorAnnounce(City* city) {
	if (city->redwarrior) {
		show_hour();
		cout<<":55 red "<<city->redwarrior->Name<<" "<<city->redwarrior->Number<<" has "
		    <<city->redwarrior->weapons.WeapNum[0]<<" sword "
		    <<city->redwarrior->weapons.WeapNum[1]<<" bomb "
		    <<city->redwarrior->weapons.WeapNum[2]<<" arrow and "
		    <<city->redwarrior->Life<<" elements"<<endl;
	}
	if (city->bluewarrior) {
		show_hour();
		cout<<":55 blue "<<city->bluewarrior->Name<<" "<<city->bluewarrior->Number<<" has "
		    <<city->bluewarrior->weapons.WeapNum[0]<<" sword "
		    <<city->bluewarrior->weapons.WeapNum[1]<<" bomb "
		    <<city->bluewarrior->weapons.WeapNum[2]<<" arrow and "
		    <<city->bluewarrior->Life<<" elements"<<endl;
	}
}

//number to string
string n_to_s (int n) {
	string res;
	stringstream ss;
	ss << n;
	ss >> res;
	return res;
}

//debug
void showWarrior (warrior* &pointer) {
	cout<<"Name:"<<pointer->Name<<" Head:"<<pointer->Head<<" Number:"<<pointer->Number<<" Life:"<<pointer->Life<<" Attack:"<<pointer->Attack<<endl;
	pointer->weapons.weap_show();
}

int main() {
	int TestNumber;
	cin>>TestNumber;
	for (int cas=1; cas<=TestNumber; ++cas) {
		Hour=0;
		MainFlag=1;
		int headLife, cityNumber, maxHour;
		cin >> headLife >> cityNumber >> LoyaltyDecrease >> maxHour;
		for (int i=1; i<=5; i++) cin>>ini_life[i];
		for (int i=1; i<=5; i++) cin>>AttackForce[i];

		Headquarter red("red", headLife, red_ord), blue("blue", headLife, blue_ord);
		City* cities=new City [cityNumber+4];
		for (int i=0; i<cityNumber+4; ++i) {
			cities[i].redwarrior=NULL;
			cities[i].bluewarrior=NULL;
			cities[i].tempblue=NULL;
			cities[i].tempred=NULL;
			cities[i].CityName=n_to_s(i-1);
			cities[i].isHead=0;
		}
		cities[1].isHead=1;
		cities[cityNumber+2].isHead=1;     //initialize and construct

		cout<<"Case "<<cas<<":"<<endl;
		while ((Hour)*60<=maxHour) {
			if (red.pro_abl) producing(cities[1].redwarrior, red);
			if (blue.pro_abl) producing(cities[cityNumber+2].bluewarrior, blue);

			if ((Hour)*60+5<=maxHour) {
				for (int i=2; i<=cityNumber+1; ++i) {
					if (cities[i].redwarrior&&cities[i].redwarrior->LionEscape()) {
						delete cities[i].redwarrior;
						cities[i].redwarrior=NULL;
					}
					if (cities[i].bluewarrior&&cities[i].bluewarrior->LionEscape()) {
						delete cities[i].bluewarrior;
						cities[i].bluewarrior=NULL;
					}
				}
			}

			if ((Hour)*60+10<=maxHour) {
				allWarriorMove(cities, 1, cityNumber+2);
				for (int i=1; i<=cityNumber+2; ++i) warriorPlace(&cities[i]);
				if (!MainFlag) break;
			}

			if ((Hour)*60+35<=maxHour) {
				for (int i=1; i<=cityNumber+2; ++i) if (cities[i].bluewarrior&&cities[i].redwarrior) rob(&cities[i]);
			}

			if ((Hour)*60+40<=maxHour) {
				for (int i=2; i<=cityNumber+1; ++i) Battling(&cities[i], i-1);
			}

			if ((Hour)*60+50<=maxHour)
				headAnnounce(red,blue);

			if ((Hour)*60+55<=maxHour)
				for (int i=1; i<=cityNumber+2; ++i) warriorAnnounce(&cities[i]);

			Hour++;
		}
	}
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值