问题描述

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

样例输出

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

提示
题目完全超出个人能力范围,网上抄的代码,至今源代码也还没有看懂,呃,,,日后再补吧
参考网纸:http://blog.csdn.net/ckcz123/article/details/8734954
也可以看一下coursera上讨论部分的精彩见解
源码

//参考网址:http://blog.csdn.net/ckcz123/article/details/8734954
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;const int DRAGON=0,NINJIA=1,ICEMAN=2,LION=3,WOLF=4;//设置常量,类似于宏定义,以在某些场合下方面使用,比如switch语句中。
const int now_order[2][5]={{2,3,4,1,0},{3,0,1,2,4}};//红蓝总部的出兵次序
const char* s[2]={"red","blue"};//红蓝总部名称
const char* ss[5]={"dragon","ninja","iceman","lion","wolf"};//士兵名称
const char* sss[3]={"sword","bomb","arrow"};//武器名称
int need[5],order[2],number[2],_attack[5],worriors_temp[2],now_time,city_sum,total[2],arrow_attack,loyalty_minus;bool head_num[2],game_over,last_color[2];
/*
sword武器类
*/
class sword
{
private:int force;//攻击力
public:sword(int x):force(x) {}//构造函数void used() {force=(int)(force*0.8);}//sword每经过一次战斗(不论是主动攻击还是反击),就会变钝,攻击力变为本次战斗前的80% (去尾取整)。bool is_deserted() {return (force==0);}//sword攻击力变为0时,sword被武士舍弃。int get_force() {return force;}//返回攻击力值
};
/*
arrow武器类
注意:两个相邻的武士可能同时放箭把对方射死。
*/
class arrow
{
private:int used_times;//使用次数int force;//攻击力
public:arrow(int x,int y):used_times(x),force(y) {}//构造函数void used() {used_times--;}//使用一次bool is_deserted() {return (used_times==0);}//武器被舍弃int get_force() {return force;}//返回攻击力int get_used_time() {return used_times;}//返回使用次数
};
/*
武士类
*/
class worriors
{
public:worriors(int,int,int);//构造函数~worriors(){if (_sword!=NULL) delete _sword;if (_arrow!=NULL) delete _arrow;}void get_hp(int a) {hp+=a;}virtual void happy(int) {}//虚函数,用于dragonvirtual void change_morale(int) {}//虚函数,用于dragonvirtual bool will_escape() {return false;}//虚函数,用于lionvirtual void minus_loyalty() {}//虚函数,用于lionfriend class city;//友元类city
protected:int type;//士兵类型int id;//编号int hp;int color;//部落颜色int attack;sword* _sword;arrow* _arrow;bool has_bomb;
};
class dragon: public worriors
{
private:double morale;//士气
public:dragon(int _color,int _id,int _type):worriors(_color,_id,_type){morale=(double)total[_color]/(double)need[0];//dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。printf("Its morale is %.2lf\n",morale);}void happy(int _id){if (morale>0.8)printf("%.3d:40 %s dragon %d yelled in city %d\n",now_time,s[color],id,_id);//dragon 在一次在它主动进攻的战斗结束后,如果还没有战死,而且士气值大于0.8,就会欢呼。}void change_morale(int a) {morale+=((a==1)?0.2:-0.2);}//dragon每取得一次战斗的胜利(敌人被杀死),士气就会增加0.2,每经历一次未能获胜的战斗,士气值就会减少0.2。士气增减发生在欢呼之前。
};
class lion: public worriors
{
private:int loyalty;//lion 有“忠诚度”这个属性
public:lion(int _color,int _id,int _type):worriors(_color,_id,_type){loyalty=total[_color];//其初始值等于它降生之后其司令部剩余生命元的数目。printf("Its loyalty is %d\n",loyalty);}bool will_escape() {return (loyalty<=0);}//忠诚度降至0或0以下,则该lion逃离战场,永远消失。void minus_loyalty() {loyalty-=loyalty_minus;}//每经过一场未能杀死敌人的战斗,忠诚度就降低K
};
/*
城市类
*/
class city
{
private:int id;int color;int hp;int last_beat_win;int just_beat_win;
public:worriors* data[2];~city(){for (int i=0;i<=1;i++)if (data[i]!=NULL)delete data[i];}void creat(int);void input_hp() {hp+=10;};void output_hp();void beat_win(int,int,int);void beat();void draw(int);void go(city*,int);bool reach_headquater(int);void print_last_go();void escape(int);void use_bomb();void tell_weapon(int);void shoot_arrow(city*,int);int get_attack(int);int get_just_beat_win() {return just_beat_win;}void bang(int);
} citys[22];
//士兵类构造函数
worriors::worriors(int _color,int _id,int _type)
{printf("%.3d:00 %s %s %d born\n",now_time,s[_color],ss[_type],_id);//在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。total[_color]-=need[_type];id=_id;color=_color;type=_type;hp=need[_type];attack=_attack[_type];_sword=NULL;has_bomb=false;_arrow=NULL;switch(_type){case DRAGON:case ICEMAN:switch (id%3){case 0:if ((int)(attack*0.2)!=0)_sword=new sword(int(attack*0.2));break;case 1:has_bomb=true;break;default:_arrow=new arrow(3,arrow_attack);}break;case NINJIA:switch(id%3){case 0:if ((int)(attack*0.2)!=0)_sword=new sword(int(attack*0.2));has_bomb=true;break;case 1:has_bomb=true;_arrow=new arrow(3,arrow_attack);break;default:_arrow=new arrow(3,arrow_attack);if ((int)(attack*0.2)!=0)_sword=new sword(int(attack*0.2));}break;default:;}
}
void city::creat(int _id)
{last_beat_win=just_beat_win=color=-1;id=_id;hp=0;data[0]=data[1]=NULL;
}
void city::beat_win(int _color,int left_hp,int y)
{if (data[_color]->type==WOLF){if (data[_color]->_sword==NULL && data[1-_color]->_sword!=NULL)data[_color]->_sword=new sword(data[1-_color]->_sword->get_force());if (!data[_color]->has_bomb && data[1-_color]->has_bomb)data[_color]->has_bomb=true;if (data[_color]->_arrow==NULL && data[1-_color]->_arrow!=NULL)data[_color]->_arrow=new arrow(data[1-_color]->_arrow->get_used_time(),data[1-_color]->_arrow->get_force());}delete data[1-_color];data[1-_color]=NULL;if (y==1){data[_color]->change_morale(1);data[_color]->happy(id);}data[_color]->hp+=left_hp;printf("%.3d:40 %s %s %d earned %d elements for his headquarter\n",now_time,s[_color],ss[data[_color]->type],data[_color]->id,hp);worriors_temp[_color]+=hp;hp=0;just_beat_win=_color;if (color!=_color && last_beat_win==_color){color=_color;printf("%.3d:40 %s flag raised in city %d\n",now_time,s[_color],id);}last_beat_win=_color;
}
void city::output_hp()
{int turn=-1;if (data[0]!=NULL && data[1]==NULL) turn=0;if (data[1]!=NULL && data[0]==NULL) turn=1;if (turn!=-1){printf("%.3d:30 %s %s %d earned %d elements for his headquarter\n",now_time,s[turn],ss[data[turn]->type],data[turn]->id,hp);total[turn]+=hp;hp=0;}
}
void city::beat()
{int turn=1,left_hp=0,add_attack;just_beat_win=-1;if (data[0]==NULL){if (data[1]!=NULL && data[1]->hp==0){delete data[1];data[1]=NULL;}return;}if (data[1]==NULL){if (data[0]->hp==0){delete data[0];data[0]=NULL;}return;}if (color==0 || (color==-1 && id%2==1)) turn=0;if (data[turn]->hp==0 && data[1-turn]->hp==0){delete data[0];delete data[1];data[0]=data[1]=NULL;return;}if (data[turn]->hp==0){beat_win(1-turn,0,0);return;}if (data[1-turn]->hp==0){beat_win(turn,0,1);return;}printf("%.3d:40 %s %s %d ",now_time,s[turn],ss[data[turn]->type],data[turn]->id);printf("attacked %s %s %d in city %d with %d elements and force %d\n",s[1-turn],ss[data[1-turn]->type],data[1-turn]->id,id,data[turn]->hp,data[turn]->attack);if (data[1-turn]->type==LION)left_hp=data[1-turn]->hp;add_attack=get_attack(turn);data[1-turn]->hp-=data[turn]->attack+add_attack;if (data[1-turn]->hp<=0){printf("%.3d:40 %s %s %d was killed in city %d\n",now_time,s[data[1-turn]->color],ss[data[1-turn]->type],data[1-turn]->id,id);beat_win(turn,left_hp,1);return;}if (data[1-turn]->type!=NINJIA){add_attack=get_attack(1-turn);printf("%.3d:40 %s %s %d fought back against %s %s %d in city %d\n",now_time,s[1-turn],ss[data[1-turn]->type],data[1-turn]->id,s[turn],ss[data[turn]->type],data[turn]->id,id);if (data[turn]->type==LION)left_hp=data[turn]->hp;else left_hp=0;data[turn]->hp-=data[1-turn]->attack/2+add_attack;if (data[turn]->hp<=0){printf("%.3d:40 %s %s %d was killed in city %d\n",now_time,s[data[turn]->color],ss[data[turn]->type],data[turn]->id,id);beat_win(1-turn,left_hp,0);return;}}draw(turn);
}
int city::get_attack(int _color)
{int add_attack=0;if (data[_color]->_sword!=NULL){add_attack=data[_color]->_sword->get_force();data[_color]->_sword->used();if (data[_color]->_sword->is_deserted()){delete data[_color]->_sword;data[_color]->_sword=NULL;}}return add_attack;
}
void city::draw(int turn)
{data[0]->minus_loyalty();data[1]->minus_loyalty();data[turn]->change_morale(-1);data[turn]->happy(id);last_beat_win=-1;
}
void city::go(city* next,int _color)
{data[_color]=next->data[_color];if (data[_color]!=NULL && data[_color]->type==ICEMAN){if ((_color==0 && id%2==0) || (_color==1 && (city_sum-id)%2==1)){data[_color]->hp-=9;if (data[_color]->hp<=0) data[_color]->hp=1;data[_color]->attack+=20;}}
}
bool city::reach_headquater(int _color)
{if (!last_color[_color]) return false;printf("%.3d:10 %s %s %d reached %s headquarter with %d elements and force %d\n",now_time,s[_color],ss[data[_color]->type],data[_color]->id,s[1-_color],data[_color]->hp,data[_color]->attack);if (head_num[_color]) return true;head_num[_color]=true;return false;
}
void city::print_last_go()
{for (int i=0;i<=1;i++)if (data[i]!=NULL)printf("%.3d:10 %s %s %d marched to city %d with %d elements and force %d\n",now_time,s[i],ss[data[i]->type],data[i]->id,id,data[i]->hp,data[i]->attack);
}
void city::escape(int i)
{if (data[i]!=NULL && data[i]->will_escape()){printf("%.3d:05 %s lion %d ran away\n",now_time,s[i],data[i]->id);delete data[i];data[i]=NULL;}
}
void city::use_bomb()
{int turn=1;if (data[0]==NULL || data[1]==NULL || data[0]->hp==0 || data[1]->hp==0)return;if (color==0 || (color==-1 && id%2==1)) turn=0;int add_force=0;if (data[turn]->_sword!=NULL)add_force=data[turn]->_sword->get_force();if (data[1-turn]->hp<=data[turn]->attack+add_force){if (data[1-turn]->has_bomb)bang(1-turn);return;}if (data[1-turn]->type==NINJIA)return;add_force=0;if (data[1-turn]->_sword!=NULL)add_force=data[1-turn]->_sword->get_force();if (data[turn]->hp<=data[1-turn]->attack/2+add_force && data[turn]->has_bomb)bang(turn);
}
void city::bang(int turn)
{printf("%.3d:38 %s %s %d used a bomb and killed %s %s %d\n",now_time,s[turn],ss[data[turn]->type],data[turn]->id,s[1-turn],ss[data[1-turn]->type],data[1-turn]->id);delete data[0];delete data[1];data[0]=data[1]=NULL;
}
void city::tell_weapon(int _color)
{bool e=false;if (data[_color]==NULL) return;printf("%.3d:55 %s %s %d has ",now_time,s[_color],ss[data[_color]->type],data[_color]->id);if (data[_color]->_arrow!=NULL){printf("arrow(%d)",data[_color]->_arrow->get_used_time());e=true;}if (data[_color]->has_bomb){if (e) printf(",");printf("bomb");e=true;}if (data[_color]->_sword!=NULL){if (e) printf(",");printf("sword(%d)",data[_color]->_sword->get_force());e=true;}if (!e) printf("no weapon");printf("\n");
}
void city::shoot_arrow(city* next,int _color)
{if (data[_color]==NULL) return;if (data[_color]->_arrow!=NULL && next->data[1-_color]!=NULL){printf("%.3d:35 %s %s %d shot",now_time,s[_color],ss[data[_color]->type],data[_color]->id);next->data[1-_color]->hp-=data[_color]->_arrow->get_force();data[_color]->_arrow->used();if (data[_color]->_arrow->is_deserted()){delete data[_color]->_arrow;data[_color]->_arrow=NULL;}if (next->data[1-_color]->hp<=0){next->data[1-_color]->hp=0;printf(" and killed %s %s %d",s[1-_color],ss[next->data[1-_color]->type],next->data[1-_color]->id);}printf("\n");}
}
void creat()
{for (int i=0;i<=1;i++){if (total[i]>=need[now_order[i][order[i]]]){worriors* temp;number[i]++;switch (now_order[i][order[i]]){case 0:temp=new dragon(i,number[i],now_order[i][order[i]]);break;case 3:temp=new lion(i,number[i],now_order[i][order[i]]);break;default:temp=new worriors(i,number[i],now_order[i][order[i]]);}citys[((i==0)?0:(city_sum+1))].data[i]=temp;order[i]=(order[i]+1)%5;}}
}
void go_ahead()
{last_color[0]=last_color[1]=false;if (citys[city_sum].data[0]!=NULL){citys[city_sum+1].go(&citys[city_sum],0);last_color[0]=true;}for (int i=city_sum;i>=1;i--)citys[i].go(&citys[i-1],0);if (citys[1].data[1]!=NULL){citys[0].go(&citys[1],1);last_color[1]=true;}for (int i=1;i<=city_sum;i++)citys[i].go(&citys[i+1],1);citys[0].data[0]=citys[city_sum+1].data[1]=NULL;if (citys[0].reach_headquater(1)){printf("%.3d:10 red headquarter was taken\n",now_time);game_over=true;}for (int i=1;i<=city_sum;i++)citys[i].print_last_go();if (citys[city_sum+1].reach_headquater(0)){printf("%.3d:10 blue headquarter was taken\n",now_time);game_over=true;}
}
void pride()
{for (int i=1;i<=city_sum;i++){if (total[1]<8) break;if (citys[i].get_just_beat_win()==1){citys[i].data[1]->get_hp(8);total[1]-=8;}}for (int i=city_sum;i>=1;i--){if (total[0]<8) break;if (citys[i].get_just_beat_win()==0){citys[i].data[0]->get_hp(8);total[0]-=8;}}for (int i=0;i<=1;i++){total[i]+=worriors_temp[i];worriors_temp[i]=0;}
}
int main()
{int times;cin >> times;int input,total_time,already_time;for (int t=1;t<=times;t++){cin >> input >> city_sum >> arrow_attack >> loyalty_minus >> total_time;total[0]=total[1]=input;already_time=0;game_over=false;now_time=-1;number[0]=number[1]=0;order[0]=order[1]=0;head_num[0]=head_num[1]=false;for (int i=0;i<=4;i++)cin >> need[i];for (int i=0;i<=4;i++)cin >> _attack[i];printf("Case %d:\n",t);for (int i=0;i<=city_sum+1;i++)citys[i].creat(i);while (1){now_time++;creat();already_time+=5;if (already_time>total_time) break;citys[0].escape(0);for (int i=1;i<=city_sum;i++)for (int j=0;j<=1;j++)citys[i].escape(j);citys[city_sum+1].escape(1);already_time+=5;if (already_time>total_time) break;go_ahead();for (int i=1;i<=city_sum;i++)citys[i].input_hp();already_time+=20;if (game_over || already_time>total_time) break;for (int i=1;i<=city_sum;i++)citys[i].output_hp();already_time+=5;if (already_time>total_time) break;citys[1].shoot_arrow(&citys[2],0);for (int i=2;i<=city_sum-1;i++){citys[i].shoot_arrow(&citys[i+1],0);citys[i].shoot_arrow(&citys[i-1],1);}citys[city_sum].shoot_arrow(&citys[city_sum-1],1);already_time+=3;if (already_time>total_time) break;for (int i=1;i<=city_sum;i++)citys[i].use_bomb();already_time+=2;if (already_time>total_time) break;for (int i=1;i<=city_sum;i++)citys[i].beat();pride();already_time+=10;if (already_time>total_time) break;for (int i=0;i<=1;i++)printf("%.3d:50 %d elements in %s headquarter\n",now_time,total[i],s[i]);already_time+=5;if (already_time>total_time) break;for (int j=0;j<=1;j++)for (int i=0;i<=city_sum+1;i++)citys[i].tell_weapon(j);already_time+=5;if (already_time>total_time) break;}}return 0;
}

魔兽世界终极版(C++程序设计第6周)相关推荐

  1. 18.04.26 魔兽世界终极版

    A:魔兽世界终极版 描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 ).红魔军 ...

  2. 【程设】魔兽世界终极版!

    魔兽世界终极版 总时间限制:  6000ms  内存限制:  65536kB   描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为 ...

  3. 程序设计实习 魔兽世界终极版 注意及代码~

    http://cxsjsx.openjudge.cn/warcraftpractice/1/ 这个题,,怎么说呢,大bug不解释.. 超级模拟有木有.. 第一:看清题目!!!!!! 第二,如果你是直接 ...

  4. cousera of pku:魔兽世界:终极版

    做这个终极版的题目,花了大概3个礼拜的时间.做完之后,感觉立刻轻松了很多,也学到了很多.这是我第一个写的差不多2000行的程序,当然也有比较大的满足感. 首先,先说下这个题目的注意事项. 1.这个题目 ...

  5. 程序设计实习 作业3 魔兽世界终极版

    Description: 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 ).红魔军 ...

  6. 魔兽世界终极版 北京大学C++课程

     题目 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 ).红魔军的司令部算作编号为 ...

  7. 【openjudge】魔兽世界(终极版)

    第一行是取消vs的error用的 //#pragma warning(disable:4996) #include <iostream> #include <fstream> ...

  8. OpenJudge-魔兽世界终极版

    魔兽世界终极版 描述 城市 武器 Sword Bomb Arrow 武士 编号 生命值 Dragon Ninja Iceman Lion Wolf 战斗 时间线 输入 输出 样例输入 样例输出 模块代 ...

  9. 魔兽世界 - PKU[课程作业]程序设计与算法(三)C++面向对象程序设计/coursera C++程序设计_World of warcraft Project

    感觉写得挺差:代码纯原创,没有半点参考: 以后若有空打算看看老师的代码,再来修改此文,先多花点时间再别的上面 建议: 1. 耐心点,仔细理解题意 2. 做到后面,前面若有设计得不好的地方,别犹豫,赶快 ...

最新文章

  1. Hadoop(19)-MapReduce框架原理-Combiner合并
  2. ruby 发送post请求_使用Ruby发送电子邮件
  3. 关于WS-PSNR、S-PSNR、CPP-PSNR
  4. 不同php文件,不同文件构建PHP程序的正确方式
  5. [原创]java WEB学习笔记107:Spring学习---AOP切面的优先级,重用切点表达式
  6. leetcode练习旋转数组
  7. canvas绘制验证码
  8. 执行DBMS_METADATA.get_ddl报ORA-39212的解决方法
  9. 蓝桥杯题目 黑色星期五
  10. 基于8086的中断方式4*4矩阵键盘
  11. java实现冒泡算法
  12. 增强 扫描王 源码_CamScanner扫描全能王v5.15.3 安卓版
  13. UE4中的委托和事件
  14. 7-11 公约数与公倍数 (10 分)
  15. 站桩是为了理气,气顺了,人自然就不会生病
  16. 从零开始学JSON(修订版)
  17. Android 直播 直播播放器选型
  18. matlab算非齐次方程,matlab-线性代数 非齐次方程组 判断是否有唯一解
  19. 7月书讯(下)| 宝藏新书助你“乘风破浪”
  20. 解决Android Studio 的AVD中的模拟器不能用PC键盘输入的问题

热门文章

  1. 《FPGA设计实战演练》学习笔记(一)FPGA板级基础五要素电路介绍及注意事项(最小系统)
  2. 批量图片采集编辑压缩工具
  3. spark 不在 sudoers 文件中。此事将被报告。
  4. swagger easyExcel导出Excel文件打不开,文件损坏
  5. 并行insert出现library cache lock与cursor: pin S wait on X等待问题记录
  6. android汉字所占内存
  7. AWS Ec2实例挂载S3存储桶实践
  8. 手工搭建多层(多隐藏层)BP神经网络
  9. bios如何设置关闭触控板功能?
  10. NAS存储中如何启用多媒体服务器?