• 18.04.06 魔兽世界三(开战)


    描述

    魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为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为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是“时: 分”,“时”有三位,“分”有两位。样例输入

    1
    20 1 10 400
    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:50 20 elements in red headquarter
    000:50 10 elements in blue headquarter
    000:55 blue lion 1 has 0 sword 1 bomb 0 arrow and 10 elements
    001:05 blue lion 1 ran away
    001:50 20 elements in red headquarter
    001:50 10 elements in blue headquarter
    002:50 20 elements in red headquarter
    002:50 10 elements in blue headquarter
    003:50 20 elements in red headquarter
    003:50 10 elements in blue headquarter
    004:50 20 elements in red headquarter
    004:50 10 elements in blue headquarter
    005:50 20 elements in red headquarter
    005:50 10 elements in blue headquarter
    

    提示

    请注意浮点数精度误差问题。OJ上的编译器编译出来的可执行程序,在这方面和你电脑上执行的程序很可能会不一致。5 * 0.3 的结果,有的机器上可能是 15.00000001,去尾取整得到15,有的机器上可能是14.9999999,去尾取整后就变成14。因此,本题不要写 5 * 0.3,要写 5 * 3 / 10。

    来源

    Guo Wei

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <algorithm>
      4 #include <stdlib.h>
      5 #include <string>
      6 #include <memory>
      7 
      8 using namespace std;
      9 //定义各种变量
     10 int M, N, K, T;//每个司令部的初始生命元数量,城市数量,忠诚衰减量,截止时间量
     11 int r_n, b_n, r_w = 1, b_w = 1;//红蓝双方的生命元数,红蓝双方要制造的武士类型
     12 int d_str, n_str, i_str, l_str, w_str;//初始生命值
     13 int d_for, n_for, i_for, l_for, w_for;//攻击力
     14 int strmin;//几种武士中最小的生命值
     15 int hour, minute, _hour, _minute;//没有_是现在时间,有_是限定时间
     16 int flag_redcreate, flag_bluecreate, flag_redtaken, flag_bluetaken;
     17 //武器
     18 class weapon {
     19 public:
     20     int num;
     21     string name;
     22 };
     23 //司令部
     24 class base
     25 {
     26 public:
     27     string type;
     28     int warriors;
     29     int locat;//所处地
     30     int d_n, n_n, i_n, l_n, w_n;
     31     int source;//生命元
     32 };
     33 //武士
     34 class warrior {
     35 public:
     36     int str;//生命值
     37     int id;//编号
     38     int forcew[4];
     39     string type;//种类
     40     weapon weapons[4];//三种类型的武器的数量 第四种是用过的arrow
     41     int force;//战力
     42     int posi;//当前所在地点编号
     43     base*mast;//司令部
     44     int state;//状态0:逃逸或死亡 1:存活
     45     int loyalty;//忠诚值
     46                 //总体初始化
     47     void mainset(base*a) {
     48         mast = a;
     49         id = (*a).warriors;
     50         posi = (*a).locat;
     51         state = 1;
     52         loyalty = 0;
     53         for (int i = 0; i <= 3; i++)
     54         {
     55             weapons[i].num = 0;
     56         }
     57     }
     58     void subset2() {
     59         for (int i = 0; i <= 3; i++)
     60             switch (i) {
     61             case 0: {weapons[i].name = "sword"; forcew[i] = force * 2 / 10; break; }
     62             case 1: {weapons[i].name = "bomb"; forcew[i] = force * 4 / 10;  break; }
     63             case 2: {weapons[i].name = "arrow"; forcew[i] = force * 3 / 10;  break; }
     64             case 3: {weapons[i].name = "arrow";  forcew[i] = force * 3 / 10; break; }
     65             }
     66     }
     67     //细化初始化
     68     virtual void rob(warrior*sb) {}
     69     virtual void subset() = 0;
     70     virtual void yell() {};
     71     virtual void attack(warrior*sb, int weaponid) {
     72         weapons[weaponid].num--;
     73         switch (weaponid) {
     74         case 0: {sb->str -= force * 2 / 10; weapons[weaponid].num++;  break; }
     75         case 1: {sb->str -= force * 4 / 10; str -= (force * 4 / 10) / 2; break; }
     76         case 2: {sb->str -= force * 3 / 10; weapons[3].num++; break; }
     77         case 3: {sb->str -= force * 3 / 10;  break; }
     78         }
     79     }
     80     virtual void toescape() {}
     81     //行军
     82     void march();
     83     void die();
     84     void getweapon(warrior*sb) {
     85         int max0 = 10;
     86         for (int i = 0; i <= 3; i++)max0 -= weapons[i].num;
     87         for (int i = 0; i <= 3 && max0>0; i++) {
     88             for (int j = 1; j <= sb->weapons[i].num&&max0>0; j++) {
     89                 max0--;
     90                 weapons[i].num++;
     91             }
     92         }
     93     }
     94 };
     95 //城市
     96 class city {
     97 public:
     98     int soldier_n;
     99     warrior* red;
    100     warrior* blue;
    101 }allcity[30];
    102 //行军
    103 void warrior::march() {
    104     if (type == "iceman")
    105     {
    106         str -= str / 10;
    107         if (str <= 0)
    108             die();
    109     }
    110     if (type == "lion")
    111         loyalty -= K;
    112     if ((*mast).type == "red"&&state)
    113         posi++;
    114     else if ((*mast).type == "blue"&&state)
    115         posi--;
    116 }
    117 void warrior::die() {
    118     allcity[posi].soldier_n--;
    119     if ((*mast).type == "red")
    120         allcity[posi].red = NULL;
    121     if ((*mast).type == "blue")
    122         allcity[posi].blue = NULL;
    123     posi = -1;
    124     state = 0;
    125 }
    126 //武士-dragon
    127 class dragon :public warrior {
    128 public:
    129     void subset() {
    130         str = d_str;
    131         type = "dragon";
    132         weapons[id % 3].num++;
    133         force = d_for;
    134     }
    135     void yell() {
    136         printf("%03d:%02d %s dragon %d yelled in city %d
    ", hour, minute, (*mast).type.c_str(), id, posi);
    137     }
    138 };
    139 //武士-ninja
    140 class ninja :public warrior {
    141 public:
    142     void subset() {
    143         str = n_str;
    144         type = "ninja";
    145         weapons[id % 3].num++;
    146         weapons[(id + 1) % 3].num++;
    147         force = n_for;
    148     }
    149     void attack(warrior*sb, int weaponid) {
    150         weapons[weaponid].num--;
    151         switch (weaponid) {
    152         case 0: {sb->str -= force * 2 / 10; weapons[weaponid].num++;   break; }
    153         case 1: {sb->str -= force * 4 / 10;  break; }
    154         case 2: {sb->str -= force * 3 / 10; weapons[3].num++; break; }
    155         case 3: {sb->str -= force * 3 / 10;  break; }
    156         }
    157     }
    158 };
    159 //武士-iceman
    160 class iceman :public warrior {
    161 public:
    162     void subset() {
    163         str = i_str;
    164         type = "iceman";
    165         weapons[id % 3].num++;
    166         force = i_for;
    167     }
    168     void yell() {}
    169 };
    170 //武士-wolf
    171 class wolf :public warrior {
    172 public:
    173     void subset() {
    174         str = w_str;
    175         type = "wolf";
    176         force = w_for;
    177     }
    178     void rob(warrior*sb)//抢夺武器
    179     {
    180         int max0 = 10;
    181         for (int i = 0; i <= 3; i++)max0 -= weapons[i].num;
    182         if (max0 && (sb->weapons[0].num + sb->weapons[1].num + sb->weapons[2].num + sb->weapons[3].num))
    183         {
    184             for (int i = 0; i <= 2; i++)
    185             {
    186                 if ((i == 0 || i == 1) && sb->weapons[i].num != 0) {
    187                     int get = min(max0, sb->weapons[i].num);
    188                     sb->weapons[i].num -= get;
    189                     weapons[i].num += get;
    190                     printf("%03d:%02d %s wolf %d took %d %s from %s %s %d in city %d
    ", hour, minute, ((*mast).type).c_str(), id, get, weapons[i].name.c_str(), ((*(sb->mast)).type).c_str(), (sb->type).c_str(), sb->id, posi);
    191                     break;
    192                 }
    193                 else if (i == 2) {
    194                     int get = min(max0, sb->weapons[i].num + sb->weapons[i + 1].num);
    195                     int extra = get - sb->weapons[i].num;
    196                     if (extra > 0) {
    197                         weapons[i].num += sb->weapons[i].num;
    198                         weapons[3].num += extra;
    199                         sb->weapons[i].num = 0;
    200                         sb->weapons[i + 1].num -= extra;
    201                     }
    202                     else {
    203                         sb->weapons[i].num -= get;
    204                         weapons[i].num += get;
    205                     }
    206                     printf("%03d:%02d %s wolf %d took %d %s from %s %s %d in city %d
    ", hour, minute, ((*mast).type).c_str(), id, get, weapons[i].name.c_str(), ((*(sb->mast)).type).c_str(), (sb->type).c_str(), sb->id, posi);
    207                 }
    208             }
    209         }
    210     }
    211     void yell() {}
    212 };
    213 //武士-lion
    214 class lion :public warrior
    215 {
    216 public:
    217     void subset() {
    218         str = l_str;
    219         type = "lion";
    220         force = l_for;
    221         weapons[id % 3].num++;
    222         loyalty = (*mast).source;
    223     }
    224     //逃跑
    225     void toescape() {
    226         state = 0;
    227         if (posi <= N&&posi >= 1)
    228         {
    229             if ((*mast).type == "red")
    230                 allcity[posi].red = NULL;
    231             else if ((*mast).type == "blue")
    232                 allcity[posi].blue = NULL;
    233             allcity[posi].soldier_n--;
    234         }
    235         posi = -1;
    236         printf("%03d:%02d ", hour, minute);
    237         cout << (*mast).type;
    238         printf(" lion %d ran away
    ", id);
    239     }
    240     void yell() {}
    241 };
    242 //循环链表:制造武士
    243 struct node {
    244     char type;
    245     node*next;
    246 };
    247 //又一波定义
    248 warrior*redwaror[1000];
    249 warrior*bluewaror[1000];
    250 dragon d_r[100], d_b[100];
    251 ninja n_r[100], n_b[100];
    252 iceman i_r[100], i_b[100];
    253 lion l_r[100], l_b[100];
    254 wolf w_r[100], w_b[100];
    255 base r;
    256 base b;
    257 node*red, *blue;
    258 node redline, redline1, redline2, redline3, redline4, blueline, blueline1, blueline2, blueline3, blueline4;
    259 void lineset() {
    260     redline.type = 'i';
    261     redline1.type = 'l';
    262     redline2.type = 'w';
    263     redline3.type = 'n';
    264     redline4.type = 'd';
    265     redline.next = &redline1;
    266     redline1.next = &redline2;
    267     redline2.next = &redline3;
    268     redline3.next = &redline4;
    269     redline4.next = &redline;
    270     blueline.type = 'l';
    271     blueline1.type = 'd';
    272     blueline2.type = 'n';
    273     blueline3.type = 'i';
    274     blueline4.type = 'w';
    275     blueline.next = &blueline1;
    276     blueline1.next = &blueline2;
    277     blueline2.next = &blueline3;
    278     blueline3.next = &blueline4;
    279     blueline4.next = &blueline;
    280     red = &redline;
    281     blue = &blueline;
    282 }
    283 //初始化
    284 void mem() {
    285     //司令部初始化
    286     red = &redline;
    287     blue = &blueline;
    288     flag_bluecreate = 1, flag_redcreate = 1;
    289     r.type = "red", b.type = "blue";
    290     r.warriors = 0, b.warriors = 0;
    291     r.locat = 0, b.locat = N + 1;
    292     r.d_n = 0, r.i_n = 0, r.l_n = 0, r.n_n = 0, r.w_n = 0;
    293     b.d_n = 0, b.i_n = 0, b.l_n = 0, b.n_n = 0, b.w_n = 0;
    294     r.source = M, b.source = M;
    295     flag_bluetaken = 0, flag_redtaken = 0;
    296     //最小初始生命值初始化
    297     strmin = min(d_str, i_str);
    298     strmin = min(strmin, n_str);
    299     strmin = min(strmin, l_str);
    300     strmin = min(strmin, w_str);
    301     //城市初始化
    302     for (int i = 0; i <= N + 1; i++)
    303     {
    304         allcity[i].soldier_n = 0;
    305         allcity[i].red = NULL;
    306         allcity[i].blue = NULL;
    307     }
    308     //时间初始化
    309     hour = 0, minute = 0;
    310     _hour = T / 60, _minute = T % 60;
    311 }
    312 //输入
    313 void init() {
    314     cin >> M >> N >> K >> T;
    315     cin >> d_str >> n_str >> i_str >> l_str >> w_str;
    316     cin >> d_for >> n_for >> i_for >> l_for >> w_for;
    317 }
    318 //制造武士
    319 void createwarriors() {
    320     if (flag_redcreate) {
    321         switch ((*red).type) {
    322         case 'i':
    323             if (r.source >= i_str) {
    324                 r.source -= i_str;
    325                 r.i_n++;
    326                 r.warriors++;
    327                 i_r[r.i_n].mainset(&r);
    328                 i_r[r.i_n].subset(); i_r[r.i_n].subset2();
    329                 redwaror[r.warriors] = &i_r[r.i_n];
    330                 printf("%03d:%02d red iceman %d born
    ", hour, minute, r.warriors);
    331                 allcity[0].soldier_n = 1;
    332                 allcity[0].red = &i_r[r.i_n];
    333                 break;
    334             }
    335             else {
    336                 flag_redcreate = 0;
    337                 break;
    338             }
    339         case 'l':
    340             if (r.source >= l_str) {
    341                 r.source -= l_str;
    342                 r.l_n++;
    343                 r.warriors++;
    344                 l_r[r.l_n].mainset(&r);
    345                 l_r[r.l_n].subset(); l_r[r.l_n].subset2();
    346                 redwaror[r.warriors] = &l_r[r.l_n];
    347                 printf("%03d:%02d red lion %d born
    ", hour, minute, r.warriors);
    348                 printf("Its loyalty is %d
    ", l_r[r.l_n].loyalty);
    349                 allcity[0].soldier_n = 1;
    350                 allcity[0].red = &l_r[r.l_n];
    351                 break;
    352             }
    353             else {
    354                 flag_redcreate = 0;
    355                 break;
    356             }
    357         case 'w':
    358             if (r.source >= w_str) {
    359                 r.source -= w_str;
    360                 r.w_n++;
    361                 r.warriors++;
    362                 w_r[r.w_n].mainset(&r);
    363                 w_r[r.w_n].subset(); w_r[r.w_n].subset2();
    364                 redwaror[r.warriors] = &w_r[r.w_n];
    365                 printf("%03d:%02d red wolf %d born
    ", hour, minute, r.warriors);
    366                 allcity[0].soldier_n = 1;
    367                 allcity[0].red = &w_r[r.w_n];
    368                 break;
    369             }
    370             else {
    371                 flag_redcreate = 0;
    372                 break;
    373             }
    374         case 'n':
    375             if (r.source >= n_str) {
    376                 r.source -= n_str;
    377                 r.n_n++;
    378                 r.warriors++;
    379                 n_r[r.n_n].mainset(&r);
    380                 n_r[r.n_n].subset(); n_r[r.n_n].subset2();
    381                 redwaror[r.warriors] = &n_r[r.n_n];
    382                 printf("%03d:%02d red ninja %d born
    ", hour, minute, r.warriors);
    383                 allcity[0].soldier_n = 1;
    384                 allcity[0].red = &n_r[r.n_n];
    385                 break;
    386             }
    387             else {
    388                 flag_redcreate = 0;
    389                 break;
    390             }
    391         case 'd':
    392             if (r.source >= d_str) {
    393                 r.source -= d_str;
    394                 r.d_n++;
    395                 r.warriors++;
    396                 d_r[r.d_n].mainset(&r);
    397                 d_r[r.d_n].subset(); d_r[r.d_n].subset2();
    398                 redwaror[r.warriors] = &d_r[r.d_n];
    399                 allcity[0].soldier_n = 1;
    400                 allcity[0].red = &d_r[r.d_n];
    401                 printf("%03d:%02d red dragon %d born
    ", hour, minute, r.warriors);
    402                 break;
    403             }
    404             else {
    405                 flag_redcreate = 0;
    406                 break;
    407             }
    408         }
    409         red = red->next;
    410     }
    411     if (flag_bluecreate) {
    412         switch ((*blue).type) {
    413         case 'i':
    414             if (b.source >= i_str) {
    415                 b.source -= i_str;
    416                 b.i_n++;
    417                 b.warriors++;
    418                 i_b[b.i_n].mainset(&b);
    419                 i_b[b.i_n].subset(); i_b[b.i_n].subset2();
    420                 bluewaror[b.warriors] = &i_b[b.i_n];
    421                 printf("%03d:%02d blue iceman %d born
    ", hour, minute, b.warriors);
    422                 allcity[N + 1].soldier_n = 1;
    423                 allcity[N + 1].blue = &i_b[b.i_n];
    424                 break;
    425             }
    426             else {
    427                 flag_bluecreate = 0;
    428                 break;
    429             }
    430         case 'l':
    431             if (b.source >= l_str) {
    432                 b.source -= l_str;
    433                 b.l_n++;
    434                 b.warriors++;
    435                 l_b[b.l_n].mainset(&b);
    436                 l_b[b.l_n].subset(); l_b[b.l_n].subset2();
    437                 bluewaror[b.warriors] = &l_b[b.l_n];
    438                 printf("%03d:%02d blue lion %d born
    ", hour, minute, b.warriors);
    439                 printf("Its loyalty is %d
    ", l_b[b.l_n].loyalty);
    440                 allcity[N + 1].soldier_n = 1;
    441                 allcity[N + 1].blue = &l_b[b.l_n];
    442                 break;
    443             }
    444             else {
    445                 flag_bluecreate = 0;
    446                 break;
    447             }
    448         case 'w':
    449             if (b.source >= w_str) {
    450                 b.source -= w_str;
    451                 b.w_n++;
    452                 b.warriors++;
    453                 w_b[b.w_n].mainset(&b);
    454                 w_b[b.w_n].subset(); w_b[b.w_n].subset2();
    455                 bluewaror[b.warriors] = &w_b[b.w_n];
    456                 printf("%03d:%02d blue wolf %d born
    ", hour, minute, b.warriors);
    457                 allcity[N + 1].soldier_n = 1;
    458                 allcity[N + 1].blue = &w_b[b.w_n];
    459                 break;
    460             }
    461             else {
    462                 flag_bluecreate = 0;
    463                 break;
    464             }
    465         case 'n':
    466             if (b.source >= n_str) {
    467                 b.source -= n_str;
    468                 b.n_n++;
    469                 b.warriors++;
    470                 n_b[b.n_n].mainset(&b);
    471                 n_b[b.n_n].subset(); n_b[b.n_n].subset2();
    472                 bluewaror[b.warriors] = &n_b[b.n_n];
    473                 printf("%03d:%02d blue ninja %d born
    ", hour, minute, b.warriors);
    474                 allcity[N + 1].soldier_n = 1;
    475                 allcity[N + 1].blue = &n_b[b.n_n];
    476                 break;
    477             }
    478             else {
    479                 flag_bluecreate = 0;
    480                 break;
    481             }
    482         case 'd':
    483             if (b.source >= d_str) {
    484                 b.source -= d_str;
    485                 b.d_n++;
    486                 b.warriors++;
    487                 d_b[b.d_n].mainset(&b);
    488                 d_b[b.d_n].subset(); d_b[b.d_n].subset2();
    489                 bluewaror[b.warriors] = &d_b[b.d_n];
    490                 printf("%03d:%02d blue dragon %d born
    ", hour, minute, b.warriors);
    491                 allcity[N + 1].soldier_n = 1;
    492                 allcity[N + 1].blue = &d_b[b.d_n];
    493                 break;
    494             }
    495             else {
    496                 flag_bluecreate = 0;
    497                 break;
    498             }
    499         }
    500         blue = blue->next;
    501     }
    502 }
    503 //狮子逃跑
    504 void lionsescape() {
    505     for (int i = 0; i <= N + 1; i++) {
    506         if (allcity[i].red != NULL)
    507         {
    508             if ((*allcity[i].red).type == "lion" && (*allcity[i].red).loyalty <= 0)
    509                 (*allcity[i].red).toescape();
    510         }
    511         if (allcity[i].blue != NULL)
    512         {
    513             if ((*allcity[i].blue).type == "lion" && (*allcity[i].blue).loyalty <= 0)
    514                 (*allcity[i].blue).toescape();
    515         }
    516     }
    517 }
    518 //行军
    519 void marching() {
    520     for (int i = 0; i <= N + 1; i++) {
    521         if (allcity[i].red)
    522             allcity[i].red->march();
    523         if (allcity[i].blue)
    524             allcity[i].blue->march();
    525     }
    526     //清空城市指针
    527     for (int i = 0; i <= N + 1; i++)
    528         allcity[i].soldier_n = 0, allcity[i].blue = NULL, allcity[i].red = NULL;
    529     for (int i = 1; i <= r.warriors; i++)
    530     {
    531         allcity[redwaror[i]->posi].soldier_n++;
    532         allcity[redwaror[i]->posi].red = redwaror[i];
    533     }
    534     for (int i = 1; i <= b.warriors; i++)
    535     {
    536         allcity[bluewaror[i]->posi].soldier_n++;
    537         allcity[bluewaror[i]->posi].blue = bluewaror[i];
    538     }
    539     for (int i = 0; i <= N + 1; i++) {
    540         if (i == 0 && allcity[i].soldier_n) {
    541             printf("%03d:%02d blue %s %d reached red headquarter with %d elements and force %d
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].blue->str, allcity[i].blue->force);
    542             printf("%03d:%02d red headquarter was taken
    ", hour, minute);
    543         }
    544         else if (i == N + 1 && allcity[i].soldier_n) {
    545             printf("%03d:%02d red %s %d reached blue headquarter with %d elements and force %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].red->str, allcity[i].red->force);
    546             printf("%03d:%02d blue headquarter was taken
    ", hour, minute);
    547         }
    548         else {
    549             if (allcity[i].red)
    550                 printf("%03d:%02d red %s %d marched to city %d with %d elements and force %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, i, allcity[i].red->str, allcity[i].red->force);
    551             if (allcity[i].blue)
    552                 printf("%03d:%02d blue %s %d marched to city %d with %d elements and force %d
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, i, allcity[i].blue->str, allcity[i].blue->force);
    553         }
    554     }
    555 }
    556 //wolf抢武器 dangerous!
    557 void wolfrobbing() {
    558     for (int i = 1; i <= N; i++)
    559     {
    560         if (allcity[i].soldier_n == 2)
    561         {
    562             if (allcity[i].red&&allcity[i].red->type == "wolf")
    563             {
    564                 if (allcity[i].blue->type != "wolf")
    565                     allcity[i].red->rob(allcity[i].blue);
    566             }
    567             else if (allcity[i].blue&&allcity[i].blue->type == "wolf")
    568             {
    569                 allcity[i].blue->rob(allcity[i].red);
    570             }
    571         }
    572     }
    573 }
    574 //战斗
    575 void battle() {
    576     for (int i = 1; i <= N; i++)
    577     {
    578         if (allcity[i].soldier_n == 2) {
    579             int countr[4] = { allcity[i].red->weapons[0].num,allcity[i].red->weapons[1].num,allcity[i].red->weapons[2].num ,allcity[i].red->weapons[3].num };
    580             int countb[4] = { allcity[i].blue->weapons[0].num,allcity[i].blue->weapons[1].num,allcity[i].blue->weapons[2].num ,allcity[i].blue->weapons[3].num };
    581             while (1) {
    582                 int weapr = -1, weapb = -1;
    583                 int flagr = 0, flagb = 0;
    584                 if (countr[0] + countr[1] + countr[2] + countr[3] == 0)
    585                     for (int j = 0; j <= 3; j++)countr[j] = allcity[i].red->weapons[j].num;
    586                 if (countr[1] + countr[2] + countr[3] == 0)flagr = 1;
    587                 if (countb[0] + countb[1] + countb[2] + countb[3] == 0)
    588                     for (int j = 0; j <= 3; j++)countb[j] = allcity[i].blue->weapons[j].num;
    589                 if (countb[1] + countb[2] + countb[3] == 0)flagb = 1;
    590                 for (int j = 0; j <= 1; j++) {
    591                     if (countr[j])
    592                     {
    593                         weapr = j;
    594                         countr[j]--;
    595                         break;
    596                     }
    597                 }
    598                 if (weapr == -1) {
    599                     if (countr[3])
    600                     {
    601                         weapr = 3; countr[3]--;
    602                     }
    603                     else if (countr[2])
    604                     {
    605                         weapr = 2; countr[2]--;
    606                     }
    607                 }
    608                 for (int j = 0; j <= 1; j++) {
    609                     if (countb[j])
    610                     {
    611                         weapb = j;
    612                         countb[j]--;
    613                         break;
    614                     }
    615                 }
    616                 if (weapb == -1) {
    617                     if (countb[3])
    618                     {
    619                         weapb = 3; countb[3]--;
    620                     }
    621                     else if (countb[2])
    622                     {
    623                         weapb = 2; countb[2]--;
    624                     }
    625                 }
    626                 if ((weapb == -1 && weapr == -1) || (weapr == 0 && weapb == 0 && allcity[i].red->forcew[weapr] == 0 && allcity[i].blue->forcew[weapb] == 0 && flagr&&flagb) || (flagb&&weapb == 0 && weapr == -1 && allcity[i].blue->forcew[weapb] == 0) || (flagr&&weapr == 0 && weapb == -1 && allcity[i].red->forcew[weapr] == 0))
    627                 {
    628                     printf("%03d:%02d both red %s %d and blue %s %d were alive in city %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i);
    629                     break;
    630                 }
    631                 if (i % 2)
    632                 {
    633                     if (weapr >= 0)
    634                     {
    635                         allcity[i].red->attack(allcity[i].blue, weapr);
    636                         if (allcity[i].blue->str <= 0 && allcity[i].red->str <= 0) {
    637                             printf("%03d:%02d both red %s %d and blue %s %d died in city %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i);
    638                             allcity[i].blue->die();
    639                             allcity[i].red->die();
    640                             break;
    641                         }
    642                         if (allcity[i].blue->str <= 0) {
    643                             allcity[i].red->getweapon(allcity[i].blue);
    644                             printf("%03d:%02d red %s %d killed blue %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i, allcity[i].red->str);
    645                             allcity[i].blue->die();
    646                             break;
    647                         }
    648                         if (allcity[i].red->str <= 0) {
    649                             allcity[i].blue->getweapon(allcity[i].red);
    650                             printf("%03d:%02d blue %s %d killed red %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].red->type.c_str(), allcity[i].red->id, i, allcity[i].blue->str);
    651                             allcity[i].red->die();
    652                             break;
    653                         }
    654                     }
    655                     if (allcity[i].blue->str > 0 && weapb >= 0)
    656                     {
    657                         allcity[i].blue->attack(allcity[i].red, weapb);
    658                         if (allcity[i].blue->str <= 0 && allcity[i].red->str <= 0) {
    659                             printf("%03d:%02d both red %s %d and blue %s %d died in city %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i);
    660                             allcity[i].blue->die();
    661                             allcity[i].red->die();
    662                             break;
    663                         }
    664                         if (allcity[i].red->str <= 0) {
    665                             allcity[i].blue->getweapon(allcity[i].red);
    666                             printf("%03d:%02d blue %s %d killed red %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].red->type.c_str(), allcity[i].red->id, i, allcity[i].blue->str);
    667                             allcity[i].red->die();
    668                             break;
    669                         }
    670                         if (allcity[i].blue->str <= 0) {
    671                             allcity[i].red->getweapon(allcity[i].blue);
    672                             printf("%03d:%02d red %s %d killed blue %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i, allcity[i].red->str);
    673                             allcity[i].blue->die();
    674                             break;
    675                         }
    676                     }
    677                 }
    678                 else {
    679                     if (weapb >= 0)
    680                     {
    681                         allcity[i].blue->attack(allcity[i].red, weapb);
    682                         if (allcity[i].blue->str <= 0 && allcity[i].red->str <= 0) {
    683                             printf("%03d:%02d both red %s %d and blue %s %d died in city %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i);
    684                             allcity[i].blue->die();
    685                             allcity[i].red->die();
    686                             break;
    687                         }
    688                         if (allcity[i].red->str <= 0) {
    689                             allcity[i].blue->getweapon(allcity[i].red);
    690                             printf("%03d:%02d blue %s %d killed red %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].red->type.c_str(), allcity[i].red->id, i, allcity[i].blue->str);
    691                             allcity[i].red->die();
    692                             break;
    693                         }
    694                         if (allcity[i].blue->str <= 0) {
    695                             allcity[i].red->getweapon(allcity[i].blue);
    696                             printf("%03d:%02d red %s %d killed blue %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i, allcity[i].red->str);
    697                             allcity[i].blue->die();
    698                             break;
    699                         }
    700                     }
    701                     if (allcity[i].red->str > 0 && weapr >= 0)
    702                     {
    703                         allcity[i].red->attack(allcity[i].blue, weapr);
    704                         if (allcity[i].blue->str <= 0 && allcity[i].red->str <= 0) {
    705                             printf("%03d:%02d both red %s %d and blue %s %d died in city %d
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i);
    706                             allcity[i].blue->die();
    707                             allcity[i].red->die();
    708                             break;
    709                         }
    710                         if (allcity[i].blue->str <= 0) {
    711                             allcity[i].red->getweapon(allcity[i].blue);
    712                             printf("%03d:%02d red %s %d killed blue %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].blue->type.c_str(), allcity[i].blue->id, i, allcity[i].red->str);
    713                             allcity[i].blue->die();
    714                             break;
    715                         }
    716                         if (allcity[i].red->str <= 0) {
    717                             allcity[i].blue->getweapon(allcity[i].red);
    718                             printf("%03d:%02d blue %s %d killed red %s %d in city %d remaining %d elements
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].red->type.c_str(), allcity[i].red->id, i, allcity[i].blue->str);
    719                             allcity[i].red->die();
    720                             break;
    721                         }
    722                     }
    723                 }
    724             }
    725             if (allcity[i].red && (allcity[i].red)->type == "dragon")
    726                 allcity[i].red->yell();
    727             if (allcity[i].blue && (allcity[i].blue)->type == "dragon")
    728                 allcity[i].blue->yell();
    729         }
    730     }
    731 }
    732 //报告生命元数
    733 void reportsource() {
    734     printf("%03d:%02d %d elements in red headquarter
    ", hour, minute, r.source);
    735     printf("%03d:%02d %d elements in blue headquarter
    ", hour, minute, b.source);
    736 }
    737 //武士报告
    738 void reportwaror() {
    739     for (int i = 0; i <= N + 1; i++) {
    740         if (allcity[i].red)
    741             printf("%03d:%02d red %s %d has %d sword %d bomb %d arrow and %d elements
    ", hour, minute, allcity[i].red->type.c_str(), allcity[i].red->id, allcity[i].red->weapons[0].num, allcity[i].red->weapons[1].num, allcity[i].red->weapons[2].num + allcity[i].red->weapons[3].num, allcity[i].red->str);
    742         if (allcity[i].blue)
    743             printf("%03d:%02d blue %s %d has %d sword %d bomb %d arrow and %d elements
    ", hour, minute, allcity[i].blue->type.c_str(), allcity[i].blue->id, allcity[i].blue->weapons[0].num, allcity[i].blue->weapons[1].num, allcity[i].blue->weapons[2].num + allcity[i].blue->weapons[3].num, allcity[i].blue->str);
    744     }
    745 }
    746 int main()
    747 {
    748     int n;//case数
    749     cin >> n;
    750     lineset();
    751     for (int c = 1; c <= n; c++) {
    752         int a = 1;
    753         init();
    754         mem();
    755         printf("Case %d:
    ", c);
    756         while (1) {
    757             //0min
    758             minute = 0;
    759             if (hour == _hour&&minute > _minute)
    760                 break;
    761             createwarriors();
    762             //5min
    763             minute = 5;
    764             if (hour == _hour&&minute > _minute)
    765                 break;
    766             lionsescape();
    767             //10min
    768             minute = 10;
    769             if (hour == _hour&&minute > _minute)
    770                 break;
    771             marching();
    772             if (allcity[0].soldier_n || allcity[N + 1].soldier_n)
    773                 break;
    774             //35min
    775             minute = 35;
    776             if (hour == _hour&&minute > _minute)
    777                 break;
    778             wolfrobbing();
    779             //40min
    780             minute = 40;
    781             if (hour == _hour&&minute > _minute)
    782                 break;
    783             battle();
    784             //50min
    785             minute = 50;
    786             if (hour == _hour&&minute > _minute)
    787                 break;
    788             reportsource();
    789             //55min
    790             minute = 55;
    791             if (hour == _hour&&minute > _minute)
    792                 break;
    793             reportwaror();
    794             hour++;
    795         }
    796     }
    797     return 0;
    798 }
    View Code

    其实有很多可以删减的地方

    有很多东西我写上去都是后来没用到或者没必要的

    但我懒得改了

    可以试着把俩司令部弄成数组……会简单很多……省去了各种分类讨论……

    但我懒得改了……

    battle部分是我写得最乱的地方

    终极版再改吧 实在没耐心了

    老师说为了防止我们从2直接跳到终极感觉像重写一样加了3

    表示对于我来说这只是增加了一个需要从头写起的任务而已

    注定失败的战争,也要拼尽全力去打赢它; 就算输,也要输得足够漂亮。
  • 相关阅读:
    poj 3468 A Simple Problem with Integers 线段树区间更新
    poj 2096 概率dp
    JSP页面的基本结构 及声明变量
    怎样制作一个横版格斗过关游戏 Cocos2d-x 2.0.4
    块状元素与内联元素的差别
    ZOJ 3526 Weekend Party
    linux下javadoc生成文件出现中文乱码
    Centos6.0 通过devtoolset-2工具安装gcc 4.8
    fre7 offonline for firefox
    Aix Lamp openssh bash
  • 原文地址:https://www.cnblogs.com/yalphait/p/8726993.html
Copyright © 2020-2023  润新知