魔兽世界大作业

\(\qquad\!\!\)因为物院的培养方案中需要或者说鼓励大家选修理学部、信息与工程学部以及其他学部的专业核心课程,以及概率统计 (B) 的课程改革,实在是不想和大一的同学恁卷的我于这学期大三下选修了一门信科的经典课程——程序设计实习,想来系统地学习一下面对对象编程。本来选的时候是想着下半学期的算法课基本上就不用学了专精 C++ 面对对象编程,结果这学期同样碰到了课程改革,下半学期从算法课变成了 Python 和各类应用的课,虽然压力大了不少,但也能算是增长了些知识和技能吧。

\(\qquad\!\!\)魔兽世界大作业作为程序设计实习课程的经典面对对象综合练习,至少我感觉还是比较适合于面对对象编程初学者来体验设计面对对象编程的过程和思想的,所以本学期还算是比较认真地(虽然肯定有 Copilot 的功劳,但是用 AI 完成这种重复性劳动还是太棒了)全部自己原创地码&调了一整遍,还是比较有收获的。

\(\qquad\!\!\)魔兽世界的题目被分成了循序渐进的四部分——魔兽世界之一:备战、魔兽世界之二:装备、魔兽世界之三:开战和魔兽世界终极版,个人感觉“魔兽世界终极版”并没有怎么比“魔兽世界之三:开战”要难,不知道是什么原因简化了不少“魔兽世界之三:开战”中的复杂的战斗和装备的特性。具体的题目可以参见 程序设计实习MOOC OpenJudge 小组,具体的链接我也会在下面的代码前给出。

\(\qquad\!\!\)但是令我非常不理解的是,使用了这么多年这么经典的习题,在题目描述的时候还是有不少逻辑不清晰之处,需要让学生来猜,或者来构造特殊数据进行验证。很难相信这么多年的来没有同学进行相关的反馈,但是甚至在“魔兽世界终极版”中的“事件及其对应的输出样例”部分,都还缺少一次获取生命元的说明,这实在不是对于学生负责任的态度。虽然确实已经有些忘记了打代码时考虑的一些情况,还是尽量参考自己当时的注释列出一些可以作为题目补充内容的条目吧,希望能够进一步厘清题目的逻辑:

  • 魔兽世界之三:开战

    • Wolf 抢夺敌人武器时,没有给出如果对方一件武器都没有需不需要进行输出?—— 不需要
  • 魔兽世界终极版

    • 虽然已经陈述了“ 如果敌人在5分钟前已经被飞来的 arrow 射死,那么仍然视为发生了一场战斗,且战斗后应该发生的事情都会发生”,但是没有给出如果当同一座城市中相遇的双方均在5分钟前已经被飞来的 arrow 射死时应该如何处理?—— 按照未发生战斗处理

    • 如果双方在进行使用 bomb 的判断时得到的结果都是应该使用 bomb 时应该如何处理?—— 都作输出至少没错,但是在给出的样例中确实没有证据,不清楚是否会有极小的可能是数据均未涉及到这种情况。

    • 在“事件及其对应的输出样例”中应该增加:

      4) 武士取走生命元

      输出样例:000:30 blue lion 1 earned 10 elements for his headquarter 表示在 0 点 30 分,编号为 1 的蓝魔 lion 武士为司令部取走了他所在城市的 10 个生命元。

总的来说,基本上按照最正常最直觉的思路思考,而非扣题目描述中字眼里的逻辑,尽量考虑实际的图像即可得到相应的逻辑。

\(\qquad\!\!\)最后给出我本人的代码,据说魔兽世界大作业在最后是有查重的,所以仅供大家参考。而且确实因为好久不写这么长的面对对象编程的代码了,在封装和代码结构在逻辑上还是有不少不满意的地方的,例如 headquarter 类中的 warriors 数组最后还是放在了 public 中、对于 private 的成员变量有的还是定义了将引用作为返回值的成员函数、对于具体任务的逻辑细分哪部分写在主函数中哪部分写在函数中没有统一的标准、对于具体任务应该写为全局的函数中还是写为成员函数没有统一的标准、对于全局的函数中进去判断是红方还是蓝方的愚蠢操作以及各种因为最开始写的时候没注意到调代码的时候懒得改逻辑了直接加分支以代码量减少工作量造成的各种代码中的冗余等等等等,可能之后不一定我什么时候闲得没事想写一写面对对象编程但是还没有合适的例子的时候会回来改改吧哈哈哈(虽然不太可能有这种情况。


  1. 魔兽世界之一:备战/魔兽世界之一:备战

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    #include<bits/stdc++.h>
    using namespace std;

    int N, M, HP[6]; //dragon, ninja, iceman, lion, wolf 的初始生命值
    int t; //时间戳
    string warriorName[6]={"","dragon","ninja","iceman","lion","wolf"};

    class headquarter
    {
    private:
    int totalHP; //总生命元
    int currentHP; //当前生命元
    int minHP; //最小生命元
    int warriorOrder[6]; //制造武士的顺序
    int warriorNum[6]; //武士的总量
    int cnt; //制造武士的指标
    bool warrior_flag; //武士是否制造完毕

    public:
    void init(); //初始化
    void warrior_init(int (&order) [6]); //制造武士的顺序初始化
    void HP_init(int M); //HP 初始化
    void create_warrior(); //制造武士
    bool getwarrior_flag() const {return warrior_flag;}
    };
    headquarter red,blue;

    void headquarter::warrior_init(int (&order) [6]) //制造武士的顺序初始化
    {
    copy(order+1, order+6, warriorOrder+1);
    return;
    }
    void headquarter::HP_init(int M) //HP 初始化
    {
    totalHP=M;
    currentHP=totalHP;
    minHP=*min_element(HP+1,HP+6);
    return;
    }
    void headquarter::init() //初始化
    {
    cnt=1;
    warrior_flag=0;
    memset(warriorNum,0,sizeof(warriorNum));
    HP_init(M);
    return;
    }
    void headquarter::create_warrior() //制造武士
    {
    if(currentHP>=minHP)
    {
    while(currentHP<HP[warriorOrder[cnt]])
    {
    cnt=cnt%5+1;
    }
    currentHP-=HP[warriorOrder[cnt]];
    warriorNum[warriorOrder[cnt]]++;
    printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),t+1,HP[warriorOrder[cnt]],warriorNum[warriorOrder[cnt]],warriorName[warriorOrder[cnt]].c_str(),(this==&red?"red":"blue"));
    cnt=cnt%5+1;
    }
    else
    {
    printf("%03d %s headquarter stops making warriors\n",t,(this==&red?"red":"blue"));
    warrior_flag=1;
    }
    return;
    }

    int qread() //快读
    {
    int x=0,y=1;
    int ch=getchar();
    while(ch<'0'||ch>'9')
    {
    if(ch=='-')
    {
    y=-1;
    }
    ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
    x=(x<<1)+(x<<3)+(ch^48);
    ch=getchar();
    }
    return x*y;
    }

    void init() //初始化
    {
    M=qread();
    for(int i=1;i<=5;i++)
    {
    HP[i]=qread();
    }
    red.init(),blue.init();
    return;
    }

    int main()
    {
    int red_warriorOrder[6]={0,3,4,5,2,1};
    int blue_warriorOrder[6]={0,4,1,2,3,5};
    red.warrior_init(red_warriorOrder);
    blue.warrior_init(blue_warriorOrder);
    N=qread();
    for(int i=1; i<=N; i++)
    {
    init();
    printf("Case:%d\n",i);
    for(t=0;((!red.getwarrior_flag())||(!blue.getwarrior_flag()));t++)
    {
    if(!red.getwarrior_flag())
    {
    red.create_warrior();
    }
    if(!blue.getwarrior_flag())
    {
    blue.create_warrior();
    }
    }
    }
    return 0;
    }

  2. 魔兽世界之二:装备/魔兽世界之二:装备

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    #include<bits/stdc++.h>
    using namespace std;

    int N, M, HP[6]; //dragon, ninja, iceman, lion, wolf 的初始生命值
    int t; //时间戳
    string warriorName[6]={"","dragon","ninja","iceman","lion","wolf"};
    string weaponName[3]={"sword","bomb","arrow"};

    class headquarter
    {
    private:
    int totalHP; //总生命元
    int currentHP; //当前生命元
    int minHP; //最小生命元
    int warriorOrder[6]; //制造武士的顺序
    int warriorNum[6]; //武士的总量
    int warriorSum; //武士的总数
    int cnt; //制造武士的指标
    bool warrior_flag; //武士是否制造完毕

    public:
    void init(); //初始化
    void warrior_init(int (&order) [6]); //制造武士的顺序初始化
    void HP_init(int M); //HP 初始化
    void create_warrior(); //制造武士
    bool getwarrior_flag() const {return warrior_flag;}
    int getcurrentHP() const {return currentHP;}
    };
    headquarter red,blue;

    class warrior
    {
    private:
    int warriorHP; //生命值
    int warriorType; //武士类型
    int type_to_num[6]={0,1,2,1,0,0}; //武士类型映射为数量
    int weaponNum; //武器数量
    int weapon[3]; //武器种类
    public:
    void init(int type, int hp, int weapon1=-1, int weapon2=-1); //初始化武士
    int getHP() const {return warriorHP;}
    int getweapon1() const {return weapon[1];}
    int getweapon2() const {return weapon[2];}
    };

    void warrior::init(int type, int hp, int weapon1, int weapon2) //初始化武士
    {
    warriorType=type;
    warriorHP=hp;
    weaponNum=type_to_num[type];
    memset(weapon,-1,sizeof(weapon));
    weapon[1]=weapon1;
    weapon[2]=weapon2;
    return;
    }

    class dragon:public warrior
    {
    private:
    double morale; //士气
    public:
    void init(int weapon1, headquarter &color);
    double getmorale() const {return morale;}
    };

    void dragon::init(int weapon1, headquarter &color)
    {
    warrior::init(1,HP[1],weapon1);
    morale=(double)color.getcurrentHP()/(double)getHP();
    return;
    }

    class ninja:public warrior
    {
    public:
    void init(int weapon1, int weapon2, headquarter &color);
    };

    void ninja::init(int weapon1, int weapon2, headquarter &color)
    {
    warrior::init(2,HP[2],weapon1,weapon2);
    return;
    }

    class iceman:public warrior
    {
    public:
    void init(int weapon1, headquarter &color);
    };

    void iceman::init(int weapon1, headquarter &color)
    {
    warrior::init(3,HP[3],weapon1);
    return;
    };

    class lion:public warrior
    {
    private:
    int loyalty; //忠诚度
    public:
    void init(headquarter &color);
    int getloyalty() const {return loyalty;}
    };

    void lion::init(headquarter &color)
    {
    warrior::init(4,HP[4]);
    loyalty=color.getcurrentHP();
    return;
    }

    class wolf:public warrior
    {
    public:
    void init(headquarter &color);
    };

    void wolf::init(headquarter &color)
    {
    warrior::init(5,HP[5]);
    return;
    }

    void headquarter::warrior_init(int (&order) [6]) //制造武士的顺序初始化
    {
    copy(order+1, order+6, warriorOrder+1);
    return;
    }
    void headquarter::HP_init(int M) //HP 初始化
    {
    totalHP=M;
    currentHP=totalHP;
    minHP=*min_element(HP+1,HP+6);
    return;
    }
    void headquarter::init() //初始化
    {
    cnt=1;
    warrior_flag=0;
    warriorSum=0;
    memset(warriorNum,0,sizeof(warriorNum));
    HP_init(M);
    return;
    }
    void headquarter::create_warrior() //制造武士
    {
    if(currentHP>=minHP)
    {
    while(currentHP<HP[warriorOrder[cnt]])
    {
    cnt=cnt%5+1;
    }
    currentHP-=HP[warriorOrder[cnt]];
    warriorNum[warriorOrder[cnt]]++;
    int n=++warriorSum;
    printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),t+1,HP[warriorOrder[cnt]],warriorNum[warriorOrder[cnt]],warriorName[warriorOrder[cnt]].c_str(),(this==&red?"red":"blue"));
    if(warriorOrder[cnt]==1)
    {
    dragon temp;
    temp.init(n%3,*this);
    printf("It has a %s,and it's morale is %.2lf\n",weaponName[temp.getweapon1()].c_str(),temp.getmorale());
    }
    else if(warriorOrder[cnt]==2)
    {
    ninja temp;
    temp.init(n%3,(n+1)%3,*this);
    printf("It has a %s and a %s\n",weaponName[temp.getweapon1()].c_str(),weaponName[temp.getweapon2()].c_str());
    }
    else if(warriorOrder[cnt]==3)
    {
    iceman temp;
    temp.init(n%3,*this);
    printf("It has a %s\n",weaponName[temp.getweapon1()].c_str());
    }
    else if(warriorOrder[cnt]==4)
    {
    lion temp;
    temp.init(*this);
    printf("It's loyalty is %d\n",temp.getloyalty());
    }
    else if(warriorOrder[cnt]==5)
    {
    wolf temp;
    temp.init(*this);
    }
    cnt=cnt%5+1;
    }
    else
    {
    printf("%03d %s headquarter stops making warriors\n",t,(this==&red?"red":"blue"));
    warrior_flag=1;
    }
    return;
    }

    int qread() //快读
    {
    int x=0,y=1;
    int ch=getchar();
    while(ch<'0'||ch>'9')
    {
    if(ch=='-')
    {
    y=-1;
    }
    ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
    x=(x<<1)+(x<<3)+(ch^48);
    ch=getchar();
    }
    return x*y;
    }

    void init() //初始化
    {
    M=qread();
    for(int i=1;i<=5;i++)
    {
    HP[i]=qread();
    }
    red.init(),blue.init();
    return;
    }

    int main()
    {
    int red_warriorOrder[6]={0,3,4,5,2,1};
    int blue_warriorOrder[6]={0,4,1,2,3,5};
    red.warrior_init(red_warriorOrder);
    blue.warrior_init(blue_warriorOrder);
    N=qread();
    for(int i=1; i<=N; i++)
    {
    init();
    printf("Case:%d\n",i);
    for(t=0;((!red.getwarrior_flag())||(!blue.getwarrior_flag()));t++)
    {
    if(!red.getwarrior_flag())
    {
    red.create_warrior();
    }
    if(!blue.getwarrior_flag())
    {
    blue.create_warrior();
    }
    }
    }
    return 0;
    }

  3. 魔兽世界之三:开战

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <algorithm>

    using namespace std;

    int TC, M, N, K, T;
    int HP[6], Atk[6]; //dragon, ninja, iceman, lion, wolf 的初始生命值和攻击力
    int t; //表示小时的时间戳
    string warriorName[6]={"","dragon","ninja","iceman","lion","wolf"};
    string weaponName[3]={"sword","bomb","arrow"};

    class warrior;

    class headquarter
    {
    private:
    int totalHP; //总生命元
    int currentHP; //当前生命元
    int minHP; //最小生命元
    int warriorOrder[6]; //制造武士的顺序
    int warriorNum[6]; //武士的总量
    int warriorSum; //武士的总数
    int cnt; //制造武士的指标
    bool warrior_flag; //武士是否制造完毕

    public:
    warrior *warriors[22]; //各城市中武士
    void init(); //初始化
    void warrior_init(int (&order) [6]); //制造武士的顺序初始化
    void HP_init(int M); //HP 初始化
    void create_warrior(); //制造武士
    void snatch_weapon(int location); //wolf 抢夺武器
    int attack(int location, int weaponType); //攻击
    void seize_weapon(int location); //缴获武器
    void report_currentHP() const; //报告当前生命元
    bool getwarrior_flag() const {return warrior_flag;}
    int getcurrentHP() const {return currentHP;}
    };
    headquarter red,blue;

    class warrior
    {
    private:
    int warriorId; //武士编号
    int warriorHP; //生命值
    int warriorType; //武士类型
    // int warriorAtk; //攻击力
    int type_to_num[6]={0,1,2,1,0,0}; //武士类型映射为武器数量
    int weaponNum; //武器种类数
    int weapon[3]; //武器数量
    int usedArrow; //使用过的 arrow 数量
    public:
    void init(int id, int type, int hp, int weapon1=-1, int weapon2=-1); //初始化武士
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) {return;}; //虚函数初始化
    virtual double getmorale() const {return -1;};
    virtual int& getloyalty() {static int dummy=0; return dummy; }
    int getId() const {return warriorId;}
    int& getHP() {return warriorHP;}
    int getType() const {return warriorType;}
    int getweapon1() const;
    int getweapon2() const;
    int getweaponTotal() const {return weapon[0]+weapon[1]+weapon[2];}
    int& getweapon(int i) {return weapon[i];}
    int& getusedArrow() {return usedArrow;}
    void clearweapon() {memset(weapon,0,sizeof(weapon)); usedArrow=0; return;}
    virtual ~warrior() {}
    };

    void warrior::init(int id, int type, int hp, int weapon1, int weapon2) //初始化武士
    {
    warriorId=id;
    warriorType=type;
    warriorHP=hp;
    // warriorAtk=Atk[type];
    weaponNum=type_to_num[type];
    usedArrow=0;
    memset(weapon,0,sizeof(weapon));
    if(weapon1!=-1)
    {
    weapon[weapon1]++;
    }
    if(weapon2!=-1)
    {
    weapon[weapon2]++;
    }
    return;
    }

    int warrior::getweapon1() const
    {
    for(int i=0;i<3;i++)
    {
    if(weapon[i])
    {
    return i;
    }
    }
    return -1;
    }

    int warrior::getweapon2() const
    {
    for(int i=warrior::getweapon1()+1;i<3;i++)
    {
    if(weapon[i])
    {
    return i;
    }
    }
    return -1;
    }

    class dragon:public warrior //dragon 武士
    {
    private:
    double morale; //士气
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 dragon
    {
    warrior::init(id,1,HP[1],weapon1);
    morale=(double)color.getcurrentHP()/(double)getHP();
    return;
    }
    virtual double getmorale() const {return morale;}
    ~dragon() {}
    };

    class ninja:public warrior //ninja 武士
    {
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 ninja
    {
    warrior::init(id, 2,HP[2],weapon1,weapon2);
    return;
    }
    ~ninja() {}
    };

    class iceman:public warrior //iceman 武士
    {
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 iceman
    {
    warrior::init(id,3,HP[3],weapon1);
    return;
    }
    ~iceman() {}
    };

    class lion:public warrior //lion 武士
    {
    private:
    int loyalty; //忠诚度
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 lion
    {
    warrior::init(id,4,HP[4],weapon1);
    loyalty=color.getcurrentHP();
    return;
    }
    virtual int& getloyalty() {return loyalty;}
    ~lion() {}
    };

    class wolf:public warrior //wolf 武士
    {
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 wolf
    {
    warrior::init(id,5,HP[5]);
    return;
    }
    ~wolf() {}
    };

    void headquarter::warrior_init(int (&order) [6]) //制造武士的顺序初始化
    {
    copy(order+1, order+6, warriorOrder+1);
    return;
    }
    void headquarter::HP_init(int M) //HP 初始化
    {
    totalHP=M;
    currentHP=totalHP;
    minHP=*min_element(HP+1,HP+6);
    return;
    }
    void headquarter::init() //司令部初始化
    {
    cnt=1;
    warrior_flag=0;
    warriorSum=0;
    memset(warriorNum,0,sizeof(warriorNum));
    HP_init(M);
    for (int i=0; i<22; i++) //释放 warriors 数组指向的空间
    {
    if(warriors[i]!=NULL)
    {
    delete warriors[i];
    warriors[i]=NULL;
    }
    }
    return;
    }

    void headquarter::create_warrior() //制造武士
    {
    // if(currentHP>=minHP) //如果当前生命元大于最小生命元
    if(currentHP>=HP[warriorOrder[cnt]]) //如果当前生命元大于制造武士需要的生命元
    {
    // while(currentHP<HP[warriorOrder[cnt]]) //找到下一个能够制造的武士
    // {
    // cnt=cnt%5+1;
    // }
    currentHP-=HP[warriorOrder[cnt]];
    warriorNum[warriorOrder[cnt]]++;
    int n=++warriorSum; //武士编号
    // printf("%03d:00 %s %s %d born with strength %d,%d %s in %s headquarter\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),n,HP[warriorOrder[cnt]],warriorNum[warriorOrder[cnt]],warriorName[warriorOrder[cnt]].c_str(),(this==&red?"red":"blue"));
    printf("%03d:00 %s %s %d born\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),n);
    if(warriorOrder[cnt]==1) //dragon
    {
    warrior *temp=new dragon();
    temp->init(n,n%3,-1,*this);
    // printf("It has a %s,and it's morale is %.2lf\n",weaponName[temp->getweapon1()].c_str(),temp->getmorale());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==2) //ninja
    {
    warrior *temp=new ninja();
    temp->init(n,n%3,(n+1)%3,*this);
    // printf("It has a %s and a %s\n",weaponName[temp->getweapon1()].c_str(),weaponName[temp->getweapon2()].c_str());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==3) //iceman
    {
    warrior *temp=new iceman();
    temp->init(n,n%3,-1,*this);
    // printf("It has a %s\n",weaponName[temp->getweapon1()].c_str());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==4) //lion
    {
    warrior *temp=new lion();
    temp->init(n,n%3,-1,*this);
    printf("Its loyalty is %d\n",temp->getloyalty());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==5) //wolf
    {
    warrior *temp=new wolf();
    temp->init(n,-1,-1,*this);
    warriors[(this==&red?0:(N+1))]=temp;
    }
    cnt=cnt%5+1;
    }
    else
    {
    // printf("%03d %s headquarter stops making warriors\n",t,(this==&red?"red":"blue"));
    warrior_flag=1;
    }
    return;
    }

    void escape_lion() //逃跑的 lion
    {
    for(int i=0;i<=N+1;i++)
    {
    if(red.warriors[i]!=NULL&&red.warriors[i]->getType()==4&&red.warriors[i]->getloyalty()<=0)
    {
    printf("%03d:05 %s lion %d ran away\n",t,"red",red.warriors[i]->getId());
    delete red.warriors[i];
    red.warriors[i]=NULL;
    }
    if(blue.warriors[i]!=NULL&&blue.warriors[i]->getType()==4&&blue.warriors[i]->getloyalty()<=0)
    {
    printf("%03d:05 %s lion %d ran away\n",t,"blue",blue.warriors[i]->getId());
    delete blue.warriors[i];
    blue.warriors[i]=NULL;
    }
    }
    return;
    }

    bool march() //前进
    {
    bool flag=0; //是否抵达敌军司令部
    for(int i=0;i<=N+1;i++)
    {
    if(i>0&&red.warriors[i-1]!=NULL)
    {
    if(red.warriors[i-1]->getType()==4) //lion 忠诚度降低
    {
    red.warriors[i-1]->getloyalty()-=K;
    }
    else if(red.warriors[i-1]->getType()==3) //iceman 生命值减少
    {
    red.warriors[i-1]->getHP()-=red.warriors[i-1]->getHP()/10;
    }
    if(i==N+1) //红方武士抵达敌军司令部
    {
    printf("%03d:10 red %s %d reached blue headquarter with %d elements and force %d\n",t,warriorName[red.warriors[i-1]->getType()].c_str(),red.warriors[i-1]->getId(),red.warriors[i-1]->getHP(),Atk[red.warriors[i-1]->getType()]);
    printf("%03d:10 blue headquarter was taken\n",t);
    flag=1;
    }
    else
    {
    printf("%03d:10 red %s %d marched to city %d with %d elements and force %d\n",t,warriorName[red.warriors[i-1]->getType()].c_str(),red.warriors[i-1]->getId(),i,red.warriors[i-1]->getHP(),Atk[red.warriors[i-1]->getType()]);
    }
    }
    if(i<N+1&&blue.warriors[i+1]!=NULL)
    {
    if(blue.warriors[i+1]->getType()==4) //lion 忠诚度降低
    {
    blue.warriors[i+1]->getloyalty()-=K;
    }
    else if(blue.warriors[i+1]->getType()==3) //iceman 生命值减少
    {
    blue.warriors[i+1]->getHP()-=blue.warriors[i+1]->getHP()/10;
    }
    if(i==0) //蓝方武士抵达敌军司令部
    {
    printf("%03d:10 blue %s %d reached red headquarter with %d elements and force %d\n",t,warriorName[blue.warriors[i+1]->getType()].c_str(),blue.warriors[i+1]->getId(),blue.warriors[i+1]->getHP(),Atk[blue.warriors[i+1]->getType()]);
    printf("%03d:10 red headquarter was taken\n",t);
    flag=1;
    }
    else
    {
    printf("%03d:10 blue %s %d marched to city %d with %d elements and force %d\n",t,warriorName[blue.warriors[i+1]->getType()].c_str(),blue.warriors[i+1]->getId(),i,blue.warriors[i+1]->getHP(),Atk[blue.warriors[i+1]->getType()]);
    }
    }
    }
    for(int i=N;i>=0;i--) //红方武士前进
    {
    if(red.warriors[i]!=NULL)
    {
    red.warriors[i+1]=red.warriors[i];
    red.warriors[i]=NULL;
    }
    }
    for(int i=1;i<=N+1;i++) //蓝方武士前进
    {
    if(blue.warriors[i]!=NULL)
    {
    blue.warriors[i-1]=blue.warriors[i];
    blue.warriors[i]=NULL;
    }
    }
    return flag;
    }

    void headquarter::snatch_weapon(int location) //wolf 抢夺武器
    {
    headquarter *enemy=(this==&red?&blue:&red);
    for(int i=0;i<3;i++) //遍历三种武器种类
    {
    if(enemy->warriors[location]->getweapon(i))
    {
    int temp=0; //抢夺了多少件武器
    while(enemy->warriors[location]->getweapon(i)&&warriors[location]->getweaponTotal()<10) //还有这件武器并且手里的武器不超过十件
    {
    warriors[location]->getweapon(i)++;
    if(i==2&&enemy->warriors[location]->getweapon(i)-enemy->warriors[location]->getusedArrow()==0) //如果剩余的 arrow 全部是使用过的,用以实现优先抢没用过的
    {
    enemy->warriors[location]->getusedArrow()--;
    warriors[location]->getusedArrow()++;
    }
    enemy->warriors[location]->getweapon(i)--;
    temp++;
    }
    // 如果对方一件武器都没有还用输出吗?至少现在看是不需要的。
    printf("%03d:35 %s %s %d took %d %s from %s %s %d in city %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),temp,weaponName[i].c_str(),(this==&red?"blue":"red"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId(),location);
    break;
    }
    }
    }

    int headquarter::attack(int location, int weaponType) //攻击
    {
    headquarter *enemy=(this==&red?&blue:&red);
    if(weaponType==0) //sword 攻击
    {
    enemy->warriors[location]->getHP()-=Atk[warriors[location]->getType()]*2/10;
    //每次如果有武士受伤就需要判断是否死亡
    if(enemy->warriors[location]->getHP()<=0)
    return 1;
    }
    else if(weaponType==1) //bomb 攻击
    {
    enemy->warriors[location]->getHP()-=Atk[warriors[location]->getType()]*4/10;
    if(warriors[location]->getType()!=2) //ninja 使用 bomb 不会让自己受伤
    {
    warriors[location]->getHP()-=(Atk[warriors[location]->getType()]*4/10)/2;
    }
    //每次如果有武士受伤就需要判断是否死亡
    if(enemy->warriors[location]->getHP()<=0&&warriors[location]->getHP()<=0)
    return 3;
    else if(enemy->warriors[location]->getHP()<=0)
    return 1;
    else if(warriors[location]->getHP()<=0)
    return 2;
    }
    else if(weaponType==2||weaponType==3) //arrow 攻击
    {
    enemy->warriors[location]->getHP()-=Atk[warriors[location]->getType()]*3/10;
    //每次如果有武士受伤就需要判断是否死亡
    if(enemy->warriors[location]->getHP()<=0)
    return 1;
    }
    return 0;
    }

    void reset_weapon(int location, queue<int> &red_weapon, queue<int> &blue_weapon) //重置战斗后的武器情况
    {
    //先清空原先的武器
    red.warriors[location]->clearweapon();
    blue.warriors[location]->clearweapon();
    //重置战斗后的武器情况
    while(!red_weapon.empty())
    {
    red.warriors[location]->getweapon(red_weapon.front()==3?2:red_weapon.front())++; //两种 arrow 都指向 2
    if(red_weapon.front()==2) //标记使用过的 arrow
    {
    red.warriors[location]->getusedArrow()++;
    }
    red_weapon.pop();
    }
    while(!blue_weapon.empty())
    {
    blue.warriors[location]->getweapon(blue_weapon.front()==3?2:blue_weapon.front())++; //两种 arrow 都指向 2
    if(blue_weapon.front()==2) //标记使用过的 arrow
    {
    blue.warriors[location]->getusedArrow()++;
    }
    blue_weapon.pop();
    }
    return;
    }

    void headquarter::seize_weapon(int location) //缴获武器
    {
    headquarter *enemy=(this==&red?&blue:&red);
    for(int i=0;i<3;i++) //遍历三种武器种类
    {
    while(enemy->warriors[location]->getweapon(i)&&warriors[location]->getweaponTotal()<10) //还有武器并且手里的武器不超过十件
    {
    warriors[location]->getweapon(i)++;
    if(i==2&&enemy->warriors[location]->getweapon(i)-enemy->warriors[location]->getusedArrow()==0) //如果剩余的 arrow 全部是使用过的,用以实现优先抢没用过的
    {
    enemy->warriors[location]->getusedArrow()--;
    warriors[location]->getusedArrow()++;
    }
    enemy->warriors[location]->getweapon(i)--;
    }
    }
    }

    bool red_attack(int location, queue<int> &red_weapon, queue<int> &blue_weapon) //红方攻击
    {
    //使用武器
    int red_weaponType=red_weapon.front();
    red_weapon.pop();
    if(red_weaponType==0)
    red_weapon.push(0);
    else if(red_weaponType==3)
    red_weapon.push(2);
    int temp=red.attack(location,red_weaponType); //攻击的结果
    if(temp==1) //蓝方战死
    {
    printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n",t,"red",warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),"blue",warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),location,red.warriors[location]->getHP());
    reset_weapon(location,red_weapon,blue_weapon);
    red.seize_weapon(location);
    delete blue.warriors[location];
    blue.warriors[location]=NULL;
    }
    else if(temp==2) //红方战死
    {
    printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n",t,"blue",warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),"red",warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),location,blue.warriors[location]->getHP());
    reset_weapon(location,red_weapon,blue_weapon);
    blue.seize_weapon(location);
    delete red.warriors[location];
    red.warriors[location]=NULL;
    }
    else if(temp==3) //双方都死了
    {
    printf("%03d:40 both red %s %d and blue %s %d died in city %d\n",t,warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),location);
    reset_weapon(location,red_weapon,blue_weapon);
    delete red.warriors[location];
    delete blue.warriors[location];
    red.warriors[location]=NULL;
    blue.warriors[location]=NULL;
    }
    if(temp) //dragon 欢呼
    {
    if(red.warriors[location]!=NULL&&red.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"red",warriorName[1].c_str(),red.warriors[location]->getId(),location);
    }
    if(blue.warriors[location]!=NULL&&blue.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"blue",warriorName[1].c_str(),blue.warriors[location]->getId(),location);
    }
    }
    return (bool)temp; //返回是否有人战死,有人战死则战斗结束
    }

    bool blue_attack(int location, queue<int> &red_weapon, queue<int> &blue_weapon)
    {
    //使用武器
    int blue_weaponType=blue_weapon.front();
    blue_weapon.pop();
    if(blue_weaponType==0)
    blue_weapon.push(0);
    else if(blue_weaponType==3)
    blue_weapon.push(2);
    int temp=blue.attack(location,blue_weaponType); //攻击的结果
    if(temp==1) //红方战死
    {
    printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n",t,"blue",warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),"red",warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),location,blue.warriors[location]->getHP());
    reset_weapon(location,red_weapon,blue_weapon);
    blue.seize_weapon(location);
    delete red.warriors[location];
    red.warriors[location]=NULL;
    }
    else if(temp==2) //蓝方战死
    {
    printf("%03d:40 %s %s %d killed %s %s %d in city %d remaining %d elements\n",t,"red",warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),"blue",warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),location,red.warriors[location]->getHP());
    reset_weapon(location,red_weapon,blue_weapon);
    red.seize_weapon(location);
    delete blue.warriors[location];
    blue.warriors[location]=NULL;
    }
    else if(temp==3) //双方都死了
    {
    printf("%03d:40 both red %s %d and blue %s %d died in city %d\n",t,warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),location);
    reset_weapon(location,red_weapon,blue_weapon);
    delete red.warriors[location];
    delete blue.warriors[location];
    red.warriors[location]=NULL;
    blue.warriors[location]=NULL;
    }
    if(temp) //dragon 欢呼
    {
    if(red.warriors[location]!=NULL&&red.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"red",warriorName[1].c_str(),red.warriors[location]->getId(),location);
    }
    if(blue.warriors[location]!=NULL&&blue.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"blue",warriorName[1].c_str(),blue.warriors[location]->getId(),location);
    }
    }
    return (bool)temp; //返回是否有人战死,有人战死则战斗结束
    }

    bool allElements(queue<int> q) //判断武器是否全部为 sword
    {
    if(q.empty())
    return true;
    while(!q.empty())
    {
    if(q.front()!=0)
    return false;
    q.pop();
    }
    return true;
    }

    void fight(int location) //战斗
    {
    queue<int> red_weapon,blue_weapon; //战斗开始前,双方先对自己的武器排好使用顺序
    while(red.warriors[location]->getweapon(0))
    {
    red_weapon.push(0);
    red.warriors[location]->getweapon(0)--;
    }
    while(red.warriors[location]->getweapon(1))
    {
    red_weapon.push(1);
    red.warriors[location]->getweapon(1)--;
    }
    while(red.warriors[location]->getusedArrow())
    {
    red_weapon.push(2); //2 代表使用过一次的arrow
    red.warriors[location]->getweapon(2)--;
    red.warriors[location]->getusedArrow()--;
    }
    while(red.warriors[location]->getweapon(2))
    {
    red_weapon.push(3); //3 代表未使用过的arrow
    red.warriors[location]->getweapon(2)--;
    }
    while(blue.warriors[location]->getweapon(0))
    {
    blue_weapon.push(0);
    blue.warriors[location]->getweapon(0)--;
    }
    while(blue.warriors[location]->getweapon(1))
    {
    blue_weapon.push(1);
    blue.warriors[location]->getweapon(1)--;
    }
    while(blue.warriors[location]->getusedArrow())
    {
    blue_weapon.push(2); //2 代表使用过一次的arrow
    blue.warriors[location]->getweapon(2)--;
    blue.warriors[location]->getusedArrow()--;
    }
    while(blue.warriors[location]->getweapon(2))
    {
    blue_weapon.push(3); //3 代表未使用过的arrow
    blue.warriors[location]->getweapon(2)--;
    }
    while((!red_weapon.empty())||(!blue_weapon.empty())) //都还有武器就互相攻击
    {
    if(location%2==1)
    {
    if(!red_weapon.empty())
    {
    if(red_attack(location,red_weapon,blue_weapon))
    {
    return;
    }
    }
    if(!blue_weapon.empty())
    {
    if(blue_attack(location,red_weapon,blue_weapon))
    {
    return;
    }
    }
    }
    else
    {
    if(!blue_weapon.empty())
    {
    if(blue_attack(location,red_weapon,blue_weapon))
    {
    return;
    }
    }
    if(!red_weapon.empty())
    {
    if(red_attack(location,red_weapon,blue_weapon))
    {
    return;
    }
    }
    }
    //如果战斗中双方的生命值和武器的状态都不再发生变化,则战斗结束,算平局
    if(Atk[red.warriors[location]->getType()]<5&&Atk[red.warriors[location]->getType()]<5&&allElements(red_weapon)&&allElements(blue_weapon))
    {
    break;
    }
    }
    //双方武器都用完且都还活着,则战斗以平局结束
    reset_weapon(location,red_weapon,blue_weapon);
    printf("%03d:40 both red %s %d and blue %s %d were alive in city %d\n",t,warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),location);
    if(red.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"red",warriorName[1].c_str(),red.warriors[location]->getId(),location);
    }
    if(blue.warriors[location]->getType()==1)
    {
    printf("%03d:40 %s %s %d yelled in city %d\n",t,"blue",warriorName[1].c_str(),blue.warriors[location]->getId(),location);
    }
    return;
    }

    void headquarter::report_currentHP() const //司令部报告生命元数量
    {
    printf("%03d:50 %d elements in %s headquarter\n",t,currentHP,(this==&red?"red":"blue"));
    return;
    }

    void report_weapon() //武士报告情况
    {
    for(int i=0;i<=N+1;i++)
    {
    if(red.warriors[i]!=NULL)
    {
    printf("%03d:55 %s %s %d has %d sword %d bomb %d arrow and %d elements\n",t,"red",warriorName[red.warriors[i]->getType()].c_str(),red.warriors[i]->getId(),red.warriors[i]->getweapon(0),red.warriors[i]->getweapon(1),red.warriors[i]->getweapon(2),red.warriors[i]->getHP());
    }
    if(blue.warriors[i]!=NULL)
    {
    printf("%03d:55 %s %s %d has %d sword %d bomb %d arrow and %d elements\n",t,"blue",warriorName[blue.warriors[i]->getType()].c_str(),blue.warriors[i]->getId(),blue.warriors[i]->getweapon(0),blue.warriors[i]->getweapon(1),blue.warriors[i]->getweapon(2),blue.warriors[i]->getHP());
    }
    }
    return;
    }

    int qread() //快读
    {
    int x=0,y=1;
    int ch=getchar();
    while(ch<'0'||ch>'9')
    {
    if(ch=='-')
    {
    y=-1;
    }
    ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
    x=(x<<1)+(x<<3)+(ch^48);
    ch=getchar();
    }
    return x*y;
    }

    void init() //初始化
    {
    M=qread(),N=qread(),K=qread(),T=qread();
    for(int i=1;i<=5;i++)
    {
    HP[i]=qread();
    }
    for(int i=1;i<=5;i++)
    {
    Atk[i]=qread();
    }
    red.init(),blue.init();
    return;
    }

    int main()
    {
    // 从同一路径下的 datapub.in 中读取数据,输出到同一路径中的 mydatapub.out 中
    // freopen("datapub.in", "r", stdin);
    // freopen("mydatapub.out", "w", stdout);
    int red_warriorOrder[6]={0,3,4,5,2,1};
    int blue_warriorOrder[6]={0,4,1,2,3,5};
    red.warrior_init(red_warriorOrder);
    blue.warrior_init(blue_warriorOrder);
    TC=qread();
    for(int i=1; i<=TC; i++)
    {
    init();
    printf("Case %d:\n",i);
    //每小时的一系列事件,注意各事件按照时间-空间的字典序排序进行输出
    for(t=0;t<(T/60);t++)
    {
    //武士降生
    if(!red.getwarrior_flag())
    {
    red.create_warrior();
    }
    if(!blue.getwarrior_flag())
    {
    blue.create_warrior();
    }
    //lion 逃跑
    escape_lion();
    //武士前进到某一城市
    if(march())
    {
    break;
    }
    //wolf 抢敌人的武器
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    if(red.warriors[j]->getType()==5&&blue.warriors[j]->getType()!=5)
    {
    red.snatch_weapon(j);
    }
    if(red.warriors[j]->getType()!=5&&blue.warriors[j]->getType()==5)
    {
    blue.snatch_weapon(j);
    }
    }
    }
    //战斗
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    fight(j);
    }
    }
    //司令部报告生命元数量
    red.report_currentHP();
    blue.report_currentHP();
    //武士报告情况
    report_weapon();
    if(t==T/60-1) //最后一个小时
    {
    t++;
    int temp=T%60; //分钟
    if(temp>=0) //武士降生
    {
    if(!red.getwarrior_flag())
    {
    red.create_warrior();
    }
    if(!blue.getwarrior_flag())
    {
    blue.create_warrior();
    }
    }
    if(temp>=5) //lion 逃跑
    {
    escape_lion();
    }
    if(temp>=10) //武士前进到某一城市
    {
    if(march())
    {
    break;
    }
    }
    if(temp>=35) //wolf 抢敌人的武器
    {
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    if(red.warriors[j]->getType()==5&&blue.warriors[j]->getType()!=5)
    {
    red.snatch_weapon(j);
    }
    if(red.warriors[j]->getType()!=5&&blue.warriors[j]->getType()==5)
    {
    blue.snatch_weapon(j);
    }
    }
    }
    }
    if(temp>=40) //战斗
    {
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    fight(j);
    }
    }
    }
    if(temp>=50) //司令部报告生命元数量
    {
    red.report_currentHP();
    blue.report_currentHP();
    }
    if(temp>=55) //武士报告情况
    {
    report_weapon();
    }
    }
    }
    }
    return 0;
    }

  4. 魔兽世界终极版

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <algorithm>

    using namespace std;

    int TC, M, N, R, K, T;
    int HP[6], Atk[6]; //dragon, ninja, iceman, lion, wolf 的初始生命值和攻击力
    int t; //表示小时的时间戳
    string warriorName[6]={"","dragon","ninja","iceman","lion","wolf"};
    string weaponName[3]={"sword","bomb","arrow"};
    int flags[22], ele[22]; //每座城市的旗子和生命元

    class warrior;

    class headquarter
    {
    private:
    // int totalHP; //总生命元
    int currentHP; //当前生命元
    // int minHP; //最小生命元
    int tempHP; //缓存战前生命元
    int warriorOrder[6]; //制造武士的顺序
    int warriorNum[6]; //武士的总量
    int warriorSum; //武士的总数
    int cnt; //制造武士的指标
    // bool warrior_flag; //武士是否制造完毕
    bool fight[22]; //每座城市的战斗情况,若前一场战斗胜利即为 true
    bool fight_flag[22]; //本方此时战斗获胜情况

    public:
    warrior *warriors[22]; //各城市中武士
    void init(); //初始化
    void warrior_init(int (&order) [6]); //制造武士的顺序初始化
    void HP_init(int M); //HP 初始化
    void create_warrior(); //制造武士
    // void snatch_weapon(int location); //wolf 抢夺武器
    void shot(int location); //放箭
    bool usebomb(int location); //使用 bomb
    // int attack(int location, int weaponType); //攻击
    bool& getfight(int location) {return fight[location];} //获取战斗情况
    bool attack(int location); //主动进攻
    bool counterattack(int location); //被动反击
    void seize_weapon(int location); //wolf 缴获武器
    // bool getwarrior_flag() const {return warrior_flag;}
    int getcurrentHP() {return currentHP;}
    int gettempHP() const {return tempHP;} //获取缓存的生命元
    void takeHP(int location); //取走生命元
    void cacheHP() {tempHP=currentHP; return;}; //缓存当前生命元
    void rewardHP(int location); //奖励生命元
    void mark_fight(int location) {fight_flag[location]=1; return;}; //标记战斗获胜情况
    bool getfight_flag(int location) const {return fight_flag[location];} //获取战斗获胜情况
    void clear_fight_flag() {memset(fight_flag, 0, sizeof(fight_flag)); return;}; //清除战斗获胜情况
    void report_currentHP() const; //报告当前生命元
    void report_weapon() const; //武士报告武器情况
    };
    headquarter red,blue;

    class warrior
    {
    private:
    int warriorId; //武士编号
    int warriorHP; //生命值
    int warriorType; //武士类型
    int warriorAtk; //攻击力
    int type_to_num[6]={0,1,2,1,0,0}; //武士类型映射为武器数量
    int weaponNum; //武器种类数
    int weapon[3]; //武器相关性质:arrow 还可以使用几次,sword 的攻击力为多少
    // int usedArrow; //使用过的 arrow 数量
    public:
    void init(int id, int type, int hp, int weapon1=-1, int weapon2=-1); //初始化武士
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) {return;}; //虚函数初始化
    virtual double& getmorale() {static double dummy=0; return dummy;};
    virtual int& getloyalty() {static int dummy=0; return dummy;}
    virtual bool& getpace() {static bool dummy=0; return dummy;}
    int getId() const {return warriorId;}
    int& getHP() {return warriorHP;}
    int getType() const {return warriorType;}
    int& getAtk() {return warriorAtk;}
    // int getweapon1() const;
    // int getweapon2() const;
    // int getweaponTotal() const {return weapon[0]+weapon[1]+weapon[2];}
    int& getweapon(int i) {return weapon[i];}
    // int& getusedArrow() {return usedArrow;}
    // void clearweapon() {memset(weapon,0,sizeof(weapon)); usedArrow=0; return;}
    virtual ~warrior() {}
    };

    void headquarter::warrior_init(int (&order) [6]) //制造武士的顺序初始化
    {
    copy(order+1, order+6, warriorOrder+1);
    return;
    }
    void headquarter::HP_init(int M) //HP 初始化
    {
    // totalHP=M;
    currentHP=M;
    tempHP=0;
    // minHP=*min_element(HP+1,HP+6);
    return;
    }
    void headquarter::init() //司令部初始化
    {
    cnt=1;
    // warrior_flag=0;
    memset(fight, 0, sizeof(fight));
    memset(fight_flag, 0, sizeof(fight_flag));
    warriorSum=0;
    memset(warriorNum,0,sizeof(warriorNum));
    HP_init(M);
    for (int i=0; i<22; i++) //释放 warriors 数组指向的空间
    {
    if(warriors[i]!=NULL)
    {
    delete warriors[i];
    warriors[i]=NULL;
    }
    }
    return;
    }

    void warrior::init(int id, int type, int hp, int weapon1, int weapon2) //初始化武士
    {
    warriorId=id;
    warriorType=type;
    warriorHP=hp;
    warriorAtk=Atk[type];
    weaponNum=type_to_num[type];
    // usedArrow=0;
    memset(weapon,0,sizeof(weapon));
    if(!weapon1) //sword
    {
    weapon[0]=warriorAtk/5; //sword 的攻击力为攻击力的 1/5
    }
    else if(weapon1==1) //bomb
    {
    weapon[1]=1; //bomb 只能有一件
    }
    else if(weapon1==2) //arrow
    {
    weapon[2]=3; //arrow 可以使用三次
    }
    if(!weapon2) //sword
    {
    weapon[0]=warriorAtk/5; //sword 的攻击力为攻击力的 1/5
    }
    else if(weapon2==1) //bomb
    {
    weapon[1]=1; //bomb 只能有一件
    }
    else if(weapon2==2) //arrow
    {
    weapon[2]=3; //arrow 可以使用三次
    }
    return;
    }

    class dragon:public warrior //dragon 武士
    {
    private:
    double morale; //士气
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 dragon
    {
    warrior::init(id,1,HP[1],weapon1);
    morale=(double)color.getcurrentHP()/(double)getHP();
    return;
    }
    virtual double& getmorale() {return morale;}
    ~dragon() {}
    };

    class ninja:public warrior //ninja 武士
    {
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 ninja
    {
    warrior::init(id, 2,HP[2],weapon1,weapon2);
    return;
    }
    ~ninja() {}
    };

    class iceman:public warrior //iceman 武士
    {
    private:
    bool pace; //前进步数
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 iceman
    {
    warrior::init(id,3,HP[3],weapon1);
    pace=0;
    return;
    }
    virtual bool& getpace() {return pace;}
    ~iceman() {}
    };

    class lion:public warrior //lion 武士
    {
    private:
    int loyalty; //忠诚度
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 lion
    {
    warrior::init(id,4,HP[4]);
    loyalty=color.getcurrentHP();
    return;
    }
    virtual int& getloyalty() {return loyalty;}
    ~lion() {}
    };

    class wolf:public warrior //wolf 武士
    {
    public:
    virtual void init(int id, int weapon1, int weapon2, headquarter &color) //初始化 wolf
    {
    warrior::init(id,5,HP[5]);
    return;
    }
    ~wolf() {}
    };

    void headquarter::create_warrior() //制造武士
    {
    // if(currentHP>=minHP) //如果当前生命元大于最小生命元
    if(currentHP>=HP[warriorOrder[cnt]]) //如果当前生命元大于制造武士需要的生命元
    {
    // while(currentHP<HP[warriorOrder[cnt]]) //找到下一个能够制造的武士
    // {
    // cnt=cnt%5+1;
    // }
    currentHP-=HP[warriorOrder[cnt]];
    warriorNum[warriorOrder[cnt]]++;
    int n=++warriorSum; //武士编号
    // printf("%03d:00 %s %s %d born with strength %d,%d %s in %s headquarter\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),n,HP[warriorOrder[cnt]],warriorNum[warriorOrder[cnt]],warriorName[warriorOrder[cnt]].c_str(),(this==&red?"red":"blue"));
    printf("%03d:00 %s %s %d born\n",t,(this==&red?"red":"blue"),warriorName[warriorOrder[cnt]].c_str(),n);
    if(warriorOrder[cnt]==1) //dragon
    {
    warrior *temp=new dragon();
    temp->init(n,n%3,-1,*this);
    // printf("It has a %s,and it's morale is %.2lf\n",weaponName[temp->getweapon1()].c_str(),temp->getmorale());
    printf("Its morale is %.2lf\n",temp->getmorale());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==2) //ninja
    {
    warrior *temp=new ninja();
    temp->init(n,n%3,(n+1)%3,*this);
    // printf("It has a %s and a %s\n",weaponName[temp->getweapon1()].c_str(),weaponName[temp->getweapon2()].c_str());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==3) //iceman
    {
    warrior *temp=new iceman();
    temp->init(n,n%3,-1,*this);
    // printf("It has a %s\n",weaponName[temp->getweapon1()].c_str());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==4) //lion
    {
    warrior *temp=new lion();
    temp->init(n,-1,-1,*this);
    printf("Its loyalty is %d\n",temp->getloyalty());
    warriors[(this==&red?0:(N+1))]=temp;
    }
    else if(warriorOrder[cnt]==5) //wolf
    {
    warrior *temp=new wolf();
    temp->init(n,-1,-1,*this);
    warriors[(this==&red?0:(N+1))]=temp;
    }
    cnt=cnt%5+1;
    }
    // else
    // {
    // // printf("%03d %s headquarter stops making warriors\n",t,(this==&red?"red":"blue"));
    // warrior_flag=1;
    // }
    return;
    }

    void escape_lion() //逃跑的 lion
    {
    for(int i=0;i<=N+1;i++)
    {
    if(i!=N+1&&red.warriors[i]!=NULL&&red.warriors[i]->getType()==4&&red.warriors[i]->getloyalty()<=0)
    {
    printf("%03d:05 %s lion %d ran away\n",t,"red",red.warriors[i]->getId());
    delete red.warriors[i];
    red.warriors[i]=NULL;
    }
    if(i&&blue.warriors[i]!=NULL&&blue.warriors[i]->getType()==4&&blue.warriors[i]->getloyalty()<=0)
    {
    printf("%03d:05 %s lion %d ran away\n",t,"blue",blue.warriors[i]->getId());
    delete blue.warriors[i];
    blue.warriors[i]=NULL;
    }
    }
    return ;
    }

    bool march() //前进
    {
    bool flag=0; //是否抵达敌军司令部
    for(int i=0;i<=N+1;i++)
    {
    if(i>0&&red.warriors[i-1]!=NULL)
    {
    // if(red.warriors[i-1]->getType()==4) //lion 忠诚度降低
    // {
    // red.warriors[i-1]->getloyalty()-=K;
    // }
    if(red.warriors[i-1]->getType()==3) //iceman 生命值减少&攻击力增加
    {
    if(red.warriors[i-1]->getpace()) //iceman 已经前进了一步
    {
    if(red.warriors[i-1]->getHP()>9)
    {
    red.warriors[i-1]->getHP()-=9; //生命值减少 9
    }
    else
    {
    red.warriors[i-1]->getHP()=1; //生命值不能小于 1
    }
    red.warriors[i-1]->getAtk()+=20; //攻击力增加
    }
    red.warriors[i-1]->getpace()=!red.warriors[i-1]->getpace(); //iceman 前进
    // red.warriors[i-1]->getHP()-=red.warriors[i-1]->getHP()/10;
    }
    if(i==N+1) //红方武士抵达敌军司令部
    {
    printf("%03d:10 red %s %d reached blue headquarter with %d elements and force %d\n",t,warriorName[red.warriors[i-1]->getType()].c_str(),red.warriors[i-1]->getId(),red.warriors[i-1]->getHP(),red.warriors[i-1]->getAtk());
    if(red.warriors[N+1]!=NULL)
    {
    printf("%03d:10 blue headquarter was taken\n",t);
    flag=1;
    }
    }
    else
    {
    printf("%03d:10 red %s %d marched to city %d with %d elements and force %d\n",t,warriorName[red.warriors[i-1]->getType()].c_str(),red.warriors[i-1]->getId(),i,red.warriors[i-1]->getHP(),red.warriors[i-1]->getAtk());
    }
    }
    if(i<N+1&&blue.warriors[i+1]!=NULL)
    {
    // if(blue.warriors[i+1]->getType()==4) //lion 忠诚度降低
    // {
    // blue.warriors[i+1]->getloyalty()-=K;
    // }
    if(blue.warriors[i+1]->getType()==3) //iceman 生命值减少&攻击力增加
    {
    if(blue.warriors[i+1]->getpace()) //iceman 已经前进了一步
    {
    if(blue.warriors[i+1]->getHP()>9)
    {
    blue.warriors[i+1]->getHP()-=9; //生命值减少 9
    }
    else
    {
    blue.warriors[i+1]->getHP()=1; //生命值不能小于 1
    }
    blue.warriors[i+1]->getAtk()+=20; //攻击力增加
    }
    blue.warriors[i+1]->getpace()=!blue.warriors[i+1]->getpace(); //iceman 前进
    // blue.warriors[i+1]->getHP()-=blue.warriors[i+1]->getHP()/10;
    }
    if(i==0) //蓝方武士抵达敌军司令部
    {
    printf("%03d:10 blue %s %d reached red headquarter with %d elements and force %d\n",t,warriorName[blue.warriors[i+1]->getType()].c_str(),blue.warriors[i+1]->getId(),blue.warriors[i+1]->getHP(),blue.warriors[i+1]->getAtk());
    if(blue.warriors[0]!=NULL)
    {
    printf("%03d:10 red headquarter was taken\n",t);
    flag=1;
    }
    }
    else
    {
    printf("%03d:10 blue %s %d marched to city %d with %d elements and force %d\n",t,warriorName[blue.warriors[i+1]->getType()].c_str(),blue.warriors[i+1]->getId(),i,blue.warriors[i+1]->getHP(),blue.warriors[i+1]->getAtk());
    }
    }
    }
    for(int i=N;i>=0;i--) //红方武士前进
    {
    if(red.warriors[i]!=NULL)
    {
    red.warriors[i+1]=red.warriors[i];
    red.warriors[i]=NULL;
    }
    }
    for(int i=1;i<=N+1;i++) //蓝方武士前进
    {
    if(blue.warriors[i]!=NULL)
    {
    blue.warriors[i-1]=blue.warriors[i];
    blue.warriors[i]=NULL;
    }
    }
    return flag;
    }

    void headquarter::takeHP(int location) //取走生命元
    {
    currentHP+=ele[location]; //武士取走生命元
    ele[location]=0; //城市 j 的生命元清零
    return ;
    }

    void headquarter::shot(int location) //放箭
    {
    headquarter *enemy=(this==&red?&blue:&red);
    int enemy_location=(this==&red?location+1:location-1); //敌方武士所在城市
    warriors[location]->getweapon(2)--; //箭使用次数减一
    enemy->warriors[enemy_location]->getHP()-=R; //敌方武士生命值减少 R
    if(enemy->warriors[enemy_location]->getHP()<=0) //敌方武士被杀死
    {
    printf("%03d:35 %s %s %d shot and killed %s %s %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[enemy_location]->getType()].c_str(),enemy->warriors[enemy_location]->getId());
    // if(this->warriors[enemy_location]!=NULL) //我方武士存在
    // {
    enemy->warriors[enemy_location]->getHP()=-1; //敌方武士生命值置为 -1,代表五分钟前被箭射死
    // }
    // else
    // {
    // delete enemy->warriors[enemy_location]; //敌方武士被杀死,释放空间
    // enemy->warriors[enemy_location]=NULL; //敌方武士指针置空
    // }
    }
    else //敌方武士未被杀死
    {
    printf("%03d:35 %s %s %d shot\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId());
    }
    return ;
    }

    bool headquarter::usebomb(int location) //使用 bomb
    {
    headquarter *enemy=(this==&red?&blue:&red);
    if(this==&red)
    {
    if(flags[location]!=-1?flags[location]:location%2) //蓝方武士被动反击
    {
    if(enemy->warriors[location]->getType()!=2&&enemy->warriors[location]->getHP()>(warriors[location]->getAtk()+warriors[location]->getweapon(0))&&warriors[location]->getHP()<=enemy->warriors[location]->getAtk()/2+enemy->warriors[location]->getweapon(0))
    {
    warriors[location]->getweapon(1)--; //bomb 使用次数减一
    printf("%03d:38 %s %s %d used a bomb and killed %s %s %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId());
    return 1; //返回 1,表示使用了 bomb
    }
    }
    else //蓝方武士主动攻击
    {
    if(warriors[location]->getHP()<=enemy->warriors[location]->getAtk()+enemy->warriors[location]->getweapon(0))
    {
    warriors[location]->getweapon(1)--; //bomb 使用次数减一
    printf("%03d:38 %s %s %d used a bomb and killed %s %s %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId());
    return 1; //返回 1,表示使用了 bomb
    }
    }
    }
    else
    {
    if(flags[location]!=-1?flags[location]:location%2) //红方武士主动攻击
    {
    if(warriors[location]->getHP()<=enemy->warriors[location]->getAtk()+enemy->warriors[location]->getweapon(0))
    {
    warriors[location]->getweapon(1)--; //bomb 使用次数减一
    printf("%03d:38 %s %s %d used a bomb and killed %s %s %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId());
    return 1; //返回 1,表示使用了 bomb
    }
    }
    else //红方武士被动反击
    {
    if(enemy->warriors[location]->getType()!=2&&enemy->warriors[location]->getHP()>(warriors[location]->getAtk()+warriors[location]->getweapon(0))&&warriors[location]->getHP()<=enemy->warriors[location]->getAtk()/2+enemy->warriors[location]->getweapon(0))
    {
    warriors[location]->getweapon(1)--; //bomb 使用次数减一
    printf("%03d:38 %s %s %d used a bomb and killed %s %s %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId());
    return 1; //返回 1,表示使用了 bomb
    }
    }
    }
    return 0;
    }

    bool headquarter::attack(int location) //主动进攻
    {
    headquarter *enemy=(this==&red?&blue:&red);
    enemy->warriors[location]->getHP()-=(warriors[location]->getAtk()+warriors[location]->getweapon(0)); //敌方武士生命值减少
    warriors[location]->getweapon(0)=warriors[location]->getweapon(0)*4/5; //sword 的攻击力减少 1/5
    printf("%03d:40 %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId(),location,warriors[location]->getHP(),warriors[location]->getAtk());
    if(enemy->warriors[location]->getHP()<=0) //敌方武士被杀死
    {
    printf("%03d:40 %s %s %d was killed in city %d\n",t,(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId(),location);
    enemy->warriors[location]->getHP()=-1;
    return 0;
    }
    return 1;
    }
    bool headquarter::counterattack(int location) //被动反击
    {
    headquarter *enemy=(this==&red?&blue:&red);
    enemy->warriors[location]->getHP()-=(warriors[location]->getAtk()/2+warriors[location]->getweapon(0)); //敌方武士生命值减少
    warriors[location]->getweapon(0)=warriors[location]->getweapon(0)*4/5; //sword 的攻击力减少 1/5
    printf("%03d:40 %s %s %d fought back against %s %s %d in city %d\n",t,(this==&red?"red":"blue"),warriorName[warriors[location]->getType()].c_str(),warriors[location]->getId(),(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId(),location);
    if(enemy->warriors[location]->getHP()<=0) //敌方武士被杀死
    {
    printf("%03d:40 %s %s %d was killed in city %d\n",t,(enemy==&red?"red":"blue"),warriorName[enemy->warriors[location]->getType()].c_str(),enemy->warriors[location]->getId(),location);
    enemy->warriors[location]->getHP()=-1;
    return 0;
    }
    return 1;
    }
    void headquarter::seize_weapon(int location) //wolf 缴获武器
    {
    headquarter *enemy=(this==&red?&blue:&red);
    if(!warriors[location]->getweapon(0))
    {
    warriors[location]->getweapon(0)=enemy->warriors[location]->getweapon(0); //缴获 sword
    }
    if(!warriors[location]->getweapon(1))
    {
    warriors[location]->getweapon(1)=enemy->warriors[location]->getweapon(1); //缴获 bomb
    }
    if(!warriors[location]->getweapon(2))
    {
    warriors[location]->getweapon(2)=enemy->warriors[location]->getweapon(2); //缴获 arrow
    }
    return ;
    }
    void fight(int location) //战斗
    {

    if(red.warriors[location]->getHP()==-1&&blue.warriors[location]->getHP()==-1) //如果双方武士都被箭射死
    {
    //但是这个时候怎么算插旗子又是个问题,暂时按照战斗了但是平手了进行计算。
    //哦,看上去不对,因为如果双方武士都被箭射死了,那么就直接不算战斗了。
    // red.getfight(location)=0;
    // blue.getfight(location)=0;
    delete red.warriors[location]; //红方武士被杀死
    red.warriors[location]=NULL; //红方武士指针置空
    delete blue.warriors[location]; //蓝方武士被杀死
    blue.warriors[location]=NULL; //蓝方武士指针置空
    return ;
    }
    int red_lion_HP=0,blue_lion_HP=0; //lion 的原始生命值
    if(red.warriors[location]->getHP()!=-1&&blue.warriors[location]->getHP()!=-1) //如果双方武士都没有被箭射死
    {
    if(red.warriors[location]->getType()==4) //如果红方武士是 lion
    {
    red_lion_HP=red.warriors[location]->getHP(); //记录红方 lion 的生命值
    }
    if(blue.warriors[location]->getType()==4) //如果蓝方武士是 lion
    {
    blue_lion_HP=blue.warriors[location]->getHP(); //记录蓝方 lion 的生命值
    }
    if(flags[location]!=-1?flags[location]:location%2)
    {
    if(red.attack(location)&&blue.warriors[location]->getType()!=2) //红方武士主动攻击
    {
    blue.counterattack(location); //蓝方武士被动反击
    }
    }
    else
    {
    if(blue.attack(location)&&red.warriors[location]->getType()!=2) //蓝方武士主动攻击
    {
    red.counterattack(location); //红方武士被动反击
    }
    }
    }
    if(red.warriors[location]->getHP()!=-1&&blue.warriors[location]->getHP()!=-1) //如果双方均未战死
    {
    red.getfight(location)=0;
    blue.getfight(location)=0;
    if(red.warriors[location]->getType()==1) //如果红方武士是 dragon
    {
    red.warriors[location]->getmorale()-=0.2; //士气降低 0.2
    if(flags[location]!=-1?flags[location]:location%2&&red.warriors[location]->getmorale()>0.8)
    {
    printf("%03d:40 red dragon %d yelled in city %d\n",t,red.warriors[location]->getId(),location);
    }
    }
    if(blue.warriors[location]->getType()==1) //如果蓝方武士是 dragon
    {
    blue.warriors[location]->getmorale()-=0.2; //士气降低 0.2
    if(!(flags[location]!=-1?flags[location]:location%2)&&blue.warriors[location]->getmorale()>0.8)
    {
    printf("%03d:40 blue dragon %d yelled in city %d\n",t,blue.warriors[location]->getId(),location);
    }
    }
    if(red.warriors[location]->getType()==4) //如果红方武士是 lion
    {
    red.warriors[location]->getloyalty()-=K; //忠诚度降低 K
    // if(red.warriors[location]->getloyalty()<=0) //如果忠诚度小于等于 0
    // {
    // delete red.warriors[location]; //红方武士逃离战场
    // red.warriors[location]=NULL; //红方武士指针置空
    // }
    }
    if(blue.warriors[location]->getType()==4) //如果蓝方武士是 lion
    {
    blue.warriors[location]->getloyalty()-=K; //忠诚度降低 K
    // if(blue.warriors[location]->getloyalty()<=0) //如果忠诚度小于等于 0
    // {
    // delete blue.warriors[location]; //蓝方武士逃离战场
    // blue.warriors[location]=NULL; //蓝方武士指针置空
    // }
    }
    }
    if(blue.warriors[location]->getHP()==-1) //如果蓝方战死红方获胜
    {
    if(red.warriors[location]->getType()==1) //如果红方武士是 dragon
    {
    red.warriors[location]->getmorale()+=0.2; //士气提高 0.2
    if(flags[location]!=-1?flags[location]:location%2&&red.warriors[location]->getmorale()>0.8)
    {
    printf("%03d:40 red dragon %d yelled in city %d\n",t,red.warriors[location]->getId(),location);
    }
    }
    if(blue.warriors[location]->getType()==4) //如果蓝方武士是 lion
    {
    red.warriors[location]->getHP()+=blue_lion_HP; //红方武士获得蓝方 lion 的生命值
    }
    if(red.warriors[location]->getType()==5) //如果红方武士是 wolf
    {
    red.seize_weapon(location); //红方 wolf 缴获蓝方武器
    }
    red.mark_fight(location); //红方武士战胜了
    if(ele[location]>0) //如果城市中有生命元
    {
    printf("%03d:40 red %s %d earned %d elements for his headquarter\n",t,warriorName[red.warriors[location]->getType()].c_str(),red.warriors[location]->getId(),ele[location]);
    red.takeHP(location); //红方武士取走生命元
    }
    blue.getfight(location)=0;
    if(red.getfight(location)&&flags[location]!=1)
    {
    flags[location]=1; //红方武士获胜,插旗子
    printf("%03d:40 red flag raised in city %d\n",t,location);
    }
    if(!red.getfight(location))
    {
    red.getfight(location)=1; //红方武士战胜过
    }
    delete blue.warriors[location]; //蓝方武士被杀死
    blue.warriors[location]=NULL; //蓝方武士指针置空
    }
    if(red.warriors[location]->getHP()==-1) //如果红方战死蓝方获胜
    {
    if(blue.warriors[location]->getType()==1) //如果蓝方武士是 dragon
    {
    blue.warriors[location]->getmorale()+=0.2; //士气提高 0.2
    if(!(flags[location]!=-1?flags[location]:location%2)&&blue.warriors[location]->getmorale()>0.8)
    {
    printf("%03d:40 blue dragon %d yelled in city %d\n",t,blue.warriors[location]->getId(),location);
    }
    }
    if(red.warriors[location]->getType()==4) //如果红方武士是 lion
    {
    blue.warriors[location]->getHP()+=red_lion_HP; //蓝方武士获得红方 lion 的生命值
    }
    if(blue.warriors[location]->getType()==5) //如果蓝方武士是 wolf
    {
    blue.seize_weapon(location); //蓝方 wolf 缴获红方武器
    }
    blue.mark_fight(location); //蓝方武士战胜了
    if(ele[location]>0) //如果城市中有生命元
    {
    printf("%03d:40 blue %s %d earned %d elements for his headquarter\n",t,warriorName[blue.warriors[location]->getType()].c_str(),blue.warriors[location]->getId(),ele[location]);
    blue.takeHP(location); //蓝方武士取走生命元
    }
    red.getfight(location)=0;
    if(blue.getfight(location)&&flags[location]!=0)
    {
    flags[location]=0; //蓝方武士获胜,插旗子
    printf("%03d:40 blue flag raised in city %d\n",t,location);
    }
    if(!blue.getfight(location))
    {
    blue.getfight(location)=1; //蓝方武士战胜过
    }
    delete red.warriors[location]; //红方武士被杀死
    red.warriors[location]=NULL; //红方武士指针置空
    }
    return ;
    }

    void headquarter::rewardHP(int location) //奖励生命元
    {
    warriors[location]->getHP()+=8; //武士生命值增加 8
    tempHP-=8; //临时生命元减少 8
    currentHP-=8; //当前生命元增加 8
    return ;
    }

    void headquarter::report_currentHP() const //司令部报告生命元数量
    {
    printf("%03d:50 %d elements in %s headquarter\n",t,currentHP,(this==&red?"red":"blue"));
    return;
    }

    void headquarter::report_weapon() const //武士报告武器情况
    {
    for(int j=0;j<=N+1;j++)
    {
    if(warriors[j]!=NULL)
    {
    int flag=0; //是否有武器
    printf("%03d:55 %s %s %d has ",t,(this==&red?"red":"blue"),warriorName[warriors[j]->getType()].c_str(),warriors[j]->getId());
    if(warriors[j]->getweapon(2))
    {
    printf("%s(%d)",weaponName[2].c_str(),warriors[j]->getweapon(2)); //箭
    flag=1; //有武器
    }
    if(warriors[j]->getweapon(1))
    {
    if(flag) //如果此前有武器
    {
    printf(",");
    }
    printf("%s",weaponName[1].c_str()); //炸弹
    flag=1; //有武器
    }
    if(warriors[j]->getweapon(0))
    {
    if(flag) //如果此前有武器
    {
    printf(",");
    }
    printf("%s(%d)",weaponName[0].c_str(),warriors[j]->getweapon(0)); //剑
    flag=1; //有武器
    }
    if(!flag) //如果没有武器
    {
    printf("no weapon");
    }
    printf("\n");
    }
    }
    }

    int qread() //快读
    {
    int x=0,y=1;
    int ch=getchar();
    while(ch<'0'||ch>'9')
    {
    if(ch=='-')
    {
    y=-1;
    }
    ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
    x=(x<<1)+(x<<3)+(ch^48);
    ch=getchar();
    }
    return x*y;
    }

    void init() //初始化
    {
    M=qread(),N=qread(),R=qread(),K=qread(),T=qread();
    for(int i=1;i<=5;i++)
    {
    HP[i]=qread();
    }
    for(int i=1;i<=5;i++)
    {
    Atk[i]=qread();
    }
    memset(flags,-1,sizeof(flags)); //初始化 flags 数组
    memset(ele,0,sizeof(ele)); //初始化 ele 数组
    red.init(),blue.init();
    return;
    }

    int main()
    {
    // 从同一路径下的 data.in 中读取数据,输出到同一路径中的 mydata.out 中
    // freopen("data.in", "r", stdin);
    // freopen("mydata.out", "w", stdout);
    TC=qread();
    int red_warriorOrder[6]={0,3,4,5,2,1};
    int blue_warriorOrder[6]={0,4,1,2,3,5};
    red.warrior_init(red_warriorOrder);
    blue.warrior_init(blue_warriorOrder);
    for(int i=1; i<=TC; i++)
    {
    init();
    printf("Case %d:\n",i);
    //每小时的一系列事件,注意各事件按照时间-空间的字典序排序进行输出
    for(t=0;t<(T/60);t++)
    {
    //武士降生
    // if(!red.getwarrior_flag())
    // {
    red.create_warrior();
    // }
    // if(!blue.getwarrior_flag())
    // {
    blue.create_warrior();
    // }
    //lion 逃跑
    escape_lion();
    //武士前进到某一城市
    if(march())
    {
    break;
    }
    //城市产出生命元
    for(int j=1;j<=N;j++)
    {
    ele[j]+=10; //每个城市产出 10 个生命元
    }
    //武士取走生命元
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]==NULL&&ele[j]) //红方武士在城市 j,蓝方武士不在城市 j
    {
    printf("%03d:30 red %s %d earned %d elements for his headquarter\n",t,warriorName[red.warriors[j]->getType()].c_str(),red.warriors[j]->getId(),ele[j]);
    red.takeHP(j); //红方武士取走生命元
    }
    if(blue.warriors[j]!=NULL&&red.warriors[j]==NULL&&ele[j]) //蓝方武士在城市 j,红方武士不在城市 j
    {
    printf("%03d:30 blue %s %d earned %d elements for his headquarter\n",t,warriorName[blue.warriors[j]->getType()].c_str(),blue.warriors[j]->getId(),ele[j]);
    blue.takeHP(j); //蓝方武士取走生命元
    }
    }
    //武士放箭
    for(int j=1;j<=N;j++)
    {
    if(j!=N&&red.warriors[j]!=NULL&&blue.warriors[j+1]!=NULL&&red.warriors[j]->getweapon(2)) //红方武士放箭
    {
    red.shot(j); //红方武士放箭
    }
    if(j!=1&&blue.warriors[j]!=NULL&&red.warriors[j-1]!=NULL&&blue.warriors[j]->getweapon(2)) //蓝方武士放箭
    {
    blue.shot(j); //蓝方武士放箭
    }
    }
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]==NULL&&red.warriors[j]->getHP()==-1) //红方武士被箭射死
    {
    delete red.warriors[j]; //红方武士被杀死
    red.warriors[j]=NULL; //红方武士指针置空
    }
    if(blue.warriors[j]!=NULL&&red.warriors[j]==NULL&&blue.warriors[j]->getHP()==-1) //蓝方武士被箭射死
    {
    delete blue.warriors[j]; //蓝方武士被杀死
    blue.warriors[j]=NULL; //蓝方武士指针置空
    }
    }
    //武士使用 bomb
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL&&red.warriors[j]->getHP()!=-1&&blue.warriors[j]->getHP()!=-1) //红蓝双方武士在同一城市且还均存活
    {
    //如果双方都应该使用 bomb 时应该如何处理?暂时考虑都作输出。
    bool bomb_flag=0; //是否使用 bomb
    if(red.warriors[j]->getweapon(1))
    {
    bomb_flag|=red.usebomb(j); //红方武士使用 bomb
    }
    if(blue.warriors[j]->getweapon(1))
    {
    bomb_flag|=blue.usebomb(j); //蓝方武士使用 bomb
    }
    if(bomb_flag)
    {
    delete red.warriors[j]; //红方武士被杀死
    red.warriors[j]=NULL; //红方武士指针置空
    delete blue.warriors[j]; //蓝方武士被杀死
    blue.warriors[j]=NULL; //蓝方武士指针置空
    }
    }
    }
    //战斗
    red.cacheHP();
    blue.cacheHP();
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    fight(j);
    }
    }
    //因为奖励生命元的判断的空间顺序和一般不通且不需要进行输出,后置奖励生命元的过程。
    //奖励生命元
    for(int j=N;j>=1;j--)
    {
    if(red.getfight_flag(j)&&red.gettempHP()>8) //红方武士战胜过且生命元大于 8
    {
    red.rewardHP(j); //红方武士奖励生命元
    }
    }
    red.clear_fight_flag(); //清除红方武士战胜标志
    for(int j=1;j<=N;j++)
    {
    if(blue.getfight_flag(j)&&blue.gettempHP()>8) //蓝方武士战胜过且生命元大于 8
    {
    blue.rewardHP(j); //蓝方武士奖励生命元
    }
    }
    blue.clear_fight_flag(); //清除蓝方武士战胜标志
    //司令部报告生命元数量
    red.report_currentHP();
    blue.report_currentHP();
    //武士报告武器情况
    red.report_weapon();
    blue.report_weapon();
    if(t==T/60-1) //最后一个小时
    {
    t++;
    int temp=T%60; //分钟
    if(temp>=0) //武士降生
    {
    // if(!red.getwarrior_flag())
    // {
    red.create_warrior();
    // }
    // if(!blue.getwarrior_flag())
    // {
    blue.create_warrior();
    // }
    }
    if(temp>=5) //lion 逃跑
    {
    escape_lion();
    }
    if(temp>=10) //武士前进到某一城市
    {
    if(march())
    {
    break;
    }
    }
    if(temp>=20) //城市产出生命元
    {
    for(int j=1;j<=N;j++)
    {
    ele[j]+=10; //每个城市产出 10 个生命元
    }
    }
    if(temp>=30) //武士取走生命元
    {
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]==NULL&&ele[j]) //红方武士在城市 j,蓝方武士不在城市 j
    {
    printf("%03d:30 red %s %d earned %d elements for his headquarter\n",t,warriorName[red.warriors[j]->getType()].c_str(),red.warriors[j]->getId(),ele[j]);
    red.takeHP(j); //红方武士取走生命元
    }
    if(blue.warriors[j]!=NULL&&red.warriors[j]==NULL&&ele[j]) //蓝方武士在城市 j,红方武士不在城市 j
    {
    printf("%03d:30 blue %s %d earned %d elements for his headquarter\n",t,warriorName[blue.warriors[j]->getType()].c_str(),blue.warriors[j]->getId(),ele[j]);
    blue.takeHP(j); //蓝方武士取走生命元
    }
    }
    }
    if(temp>=35) //武士放箭
    {
    for(int j=1;j<=N;j++)
    {
    if(j!=N&&red.warriors[j]!=NULL&&blue.warriors[j+1]!=NULL&&red.warriors[j]->getweapon(2)) //红方武士放箭
    {
    red.shot(j); //红方武士放箭
    }
    if(j!=1&&blue.warriors[j]!=NULL&&red.warriors[j-1]!=NULL&&blue.warriors[j]->getweapon(2)) //蓝方武士放箭
    {
    blue.shot(j); //蓝方武士放箭
    }
    }
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]==NULL&&red.warriors[j]->getHP()==-1) //红方武士被箭射死
    {
    delete red.warriors[j]; //红方武士被杀死
    red.warriors[j]=NULL; //红方武士指针置空
    }
    if(blue.warriors[j]!=NULL&&red.warriors[j]==NULL&&blue.warriors[j]->getHP()==-1) //蓝方武士被箭射死
    {
    delete blue.warriors[j]; //蓝方武士被杀死
    blue.warriors[j]=NULL; //蓝方武士指针置空
    }
    }
    }
    if(temp>=38) //武士使用 bomb
    {
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL&&red.warriors[j]->getHP()!=-1&&blue.warriors[j]->getHP()!=-1) //红蓝双方武士在同一城市且还均存活
    {
    //如果双方都应该使用 bomb 时应该如何处理?暂时考虑都作输出。
    bool bomb_flag=0; //是否使用 bomb
    if(red.warriors[j]->getweapon(1))
    {
    bomb_flag|=red.usebomb(j); //红方武士使用 bomb
    }
    if(blue.warriors[j]->getweapon(1))
    {
    bomb_flag|=blue.usebomb(j); //蓝方武士使用 bomb
    }
    if(bomb_flag)
    {
    delete red.warriors[j]; //红方武士被杀死
    red.warriors[j]=NULL; //红方武士指针置空
    delete blue.warriors[j]; //蓝方武士被杀死
    blue.warriors[j]=NULL; //蓝方武士指针置空
    }
    }
    }
    }
    if(temp>=40) //战斗
    {
    red.cacheHP();
    blue.cacheHP();
    for(int j=1;j<=N;j++)
    {
    if(red.warriors[j]!=NULL&&blue.warriors[j]!=NULL)
    {
    fight(j);
    }
    }
    //因为奖励生命元的判断的空间顺序和一般不通且不需要进行输出,后置奖励生命元的过程。
    //奖励生命元
    for(int j=N;j>=1;j--)
    {
    if(red.getfight_flag(j)&&red.gettempHP()>8) //红方武士战胜过且生命元大于 8
    {
    red.rewardHP(j); //红方武士奖励生命元
    }
    }
    red.clear_fight_flag(); //清除红方武士战胜标志
    for(int j=1;j<=N;j++)
    {
    if(blue.getfight_flag(j)&&blue.gettempHP()>8) //蓝方武士战胜过且生命元大于 8
    {
    blue.rewardHP(j); //蓝方武士奖励生命元
    }
    }
    blue.clear_fight_flag(); //清除蓝方武士战胜标志
    }
    if(temp>=50) //司令部报告生命元数量
    {
    red.report_currentHP();
    blue.report_currentHP();
    }
    if(temp>=55) //武士报告武器情况
    {
    red.report_weapon();
    blue.report_weapon();
    }
    }
    }
    }
    return 0;
    }