全宇宙最帅男子

少壮不努力,长大做IT

0%

openjudge 3750:魔兽世界

描述

两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。
双方的武士编号都是从1开始计算。红方制造出来的第 n 个武士,编号就是n。同样,蓝方制造出来的第 n 个武士,编号也是n。
武士在刚降生的时候有一个初始的生命值,生命值在战斗中会发生变化,如果生命值减少到0或少于0,则武士死亡(消失)。

在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。
红方司令部按照 iceman、lion、wolf、ninja、dragon 的顺序制造武士。
蓝方司令部按照 lion、dragon、ninja、iceman、wolf 的顺序制造武士。
制造武士需要生命元。
制造一个初始生命值为 m 的武士,司令部中的生命元就要减少 m 个。
如果司令部中的生命元不足以制造某武士,那么司令部就等待,直到获得足够生命元后的第一个整点,才制造该武士。例如,在2:00,红方司令部本该制造一个 wolf ,如果此时生命元不足,那么就会等待,直到生命元足够后的下一个整点,才制造一个 wolf。
在每个小时的第 10 分:所有的武士朝敌人司令部方向前进一步。即从己方司令部走到相邻城市,或从一个城市走到下一个城市。或从和敌军司令部相邻的城市到达敌军司令部。
在每个小时的第 20 分:每个城市产出10个生命元。生命元留在城市,直到被武士取走。
在每个小时的第 30 分:如果某个城市中只有一个武士,那么该武士取走该城市中的所有生命元,并立即将这些生命元传送到其所属的司令部。
在每个小时的第 40 分:在有两个武士的城市,会发生战斗。在每个小时的第50分,司令部报告它拥有的生命元数量。
每次战斗有且只有一方武士主动进攻。被攻击者生命值会减去进攻者的攻击力值。如果被攻击者生命值减至小于等于0,则其被杀死。
如果被攻击者没有被杀死,则会发动反击,被反击者的生命值要减去反击者攻击力值的一半(去尾取整)。反击当然可能致敌人于死地。
如果武士在战斗中杀死敌人(不论是主动进攻杀死还是反击杀死),则其司令部会立即向其发送8个生命元作为奖励,使其生命值增加8。当然前提是司令部得有8个生命元。如果司令部的生命元不足以奖励所有的武士,则优先奖励距离敌方司令部近的武士。
如果某武士在某城市的战斗中杀死了敌人,则该武士的司令部立即取得该城市中所有的生命元。注意,司令部总是先奖励武士,然后再收回打了胜仗的城市的生命元。对于因司令部生命元不足而领不到奖励的武士,司令部也不会在取得战利品生命元后为其补发奖励。
每次战斗都只有一方主动进攻一次。战斗并非是你死我活的,可能是双方都幸存。如果双方都幸存,则双方都不能拿走发生战斗的城市的生命元
在插红旗的城市,以及编号为奇数的无旗城市,由红武士主动发起进攻。
在插蓝旗的城市,以及编号为偶数的无旗城市,由蓝武士主动发起进攻。
一开始所有的城市都是无旗的。当某个城市有连续两场战斗都是同一方的武士杀死敌人(两场战斗中间如果有若干个战斗时刻并没有发生战斗,则这两场战斗仍然算是连续的) ,那么该城市就会插上胜方的旗帜,若原来插着败方的旗帜,则败方旗帜落下。旗帜一旦插上,就一直插着,直到被敌人更换。一个城市最多只能插一面旗帜,旗帜没被敌人更换前,也不会再次插同颜色的旗。

不同的武士各有其特点:
dragon 在一次在它主动进攻的战斗结束后,如果还没有战死,就会欢呼。
ninja 挨打了也从不反击敌人。
iceman 每前进两步,在第2步完成的时候,生命值会减少9,攻击力会增加20。但是若生命值减9后会小于等于0,则生命值不减9,而是变为1。即iceman不会因走多了而死。
lion 若是战死,则其战斗前的生命值就会转移到对手身上。
在一个 wolf 通过主动攻击杀死敌人的次数达到偶数的时刻(次数从1开始算),在战斗完成后,该 wolf 生命值和攻击力都增加1倍。如果其杀死的敌人是lion,则攻击力和生命值先加倍,然后才吸取lion的生命值。获取总部的生命元奖励,发生在加倍之后。只有在主动攻击杀死敌人时才能有加倍的事情,反击杀死敌人则不不会发生加倍。
武士到达对方司令部后就算完成任务了,从此就呆在那里无所事事。
任何一方的司令部里若是出现了2个敌人,则认为该司令部已被敌人占领。
任何一方的司令部被敌人占领,则战争结束。战争结束之后就不会发生任何事情了。

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

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
1) 武士降生
输出样例: 000:00 blue lion 1 born
表示在 0点0分,编号为1的蓝魔lion武士降生

2) 武士前进到某一城市
输出样例: 000:10 red iceman 1 marched to city 1 with 20 elements and force 30
表示在 0点10分,红魔1号武士iceman前进到1号城市,此时他生命值为20,攻击力为30
对于iceman,输出的生命值和攻击力应该是变化后的数值

3) 武士主动进攻
输出样例:000:40 red iceman 1 attacked blue lion 1 in city 1 with 20 elements and force 30
表示在0点40分,1号城市中,红魔1号武士iceman 进攻蓝魔1号武士lion,在发起进攻前,红魔1号武士iceman生命值为20,攻击力为 30

4) 武士反击
输出样例:001:40 blue dragon 2 fought back against red lion 2 in city 1
表示在1点40分,1号城市中,蓝魔2号武士dragon反击红魔2号武士lion

5) 武士战死
输出样例:001:40 red lion 2 was killed in city 1

6) 武士欢呼
输出样例:003:40 blue dragon 2 yelled in city 4

7) 武士获取生命元( elements )
输出样例:001:40 blue dragon 2 earned 10 elements for his headquarter

8) 旗帜升起
输出样例:004:40 blue flag raised in city 4

9) 武士抵达敌军司令部
输出样例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
(此时他生命值为20,攻击力为30)对于iceman,输出的生命值和攻击力应该是变化后的数值

10) 司令部被占领
输出样例:003:10 blue headquarter was taken

11)司令部报告生命元数量
000:50 100 elements in red headquarter
000:50 120 elements in blue headquarter
表示在0点50分,红方司令部有100个生命元,蓝方有120个

输出事件时:

首先按时间顺序输出;

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

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

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

显然,10号事件发生之前的一瞬间一定发生了9号事件。输出时,这两件事算同一时间发生,但是应先输出9号事件
虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
输入
第一行是一个整数,代表测试数据组数
每组测试数据共三行。

第一行,三个整数 M,N,T。其含义为:

每个司令部一开始都有M个生命元( 1 <= M <= 1000)
两个司令部之间一共有N个城市( 1 <= N <= 20 )
要求输出从0时0分开始,到时间T为止(包括T) 的所有事件。T以分钟为单位,0 <= T <= 1000

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

第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于100
输出
对每组测试数据,首先输出“Case:n" n是测试数据的编号,从1开始
接下来按恰当的顺序和格式输出到时间T为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是“时: 分”,“时”有三位,“分”有两位。
1
2
3
4
5
6
7
8
样例输入
2
99 2 1000
10 20 50 50 30
20 50 50 50 50
40 1 1000
20 20 20 20 20
20 20 20 20 20
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
样例输出
Case:1
000:00 red iceman 1 born
000:00 blue lion 1 born
000:10 red iceman 1 marched to city 1 with 50 elements and force 50
000:10 blue lion 1 marched to city 2 with 50 elements and force 50
000:30 red iceman 1 earned 10 elements for his headquarter
000:30 blue lion 1 earned 10 elements for his headquarter
000:50 59 elements in red headquarter
000:50 59 elements in blue headquarter
001:00 red lion 2 born
001:00 blue dragon 2 born
001:10 red lion 2 marched to city 1 with 50 elements and force 50
001:10 blue lion 1 marched to city 1 with 50 elements and force 50
001:10 red iceman 1 marched to city 2 with 41 elements and force 70
001:10 blue dragon 2 marched to city 2 with 10 elements and force 20
001:40 red lion 2 attacked blue lion 1 in city 1 with 50 elements and force 50
001:40 blue lion 1 was killed in city 1
001:40 red lion 2 earned 10 elements for his headquarter
001:40 blue dragon 2 attacked red iceman 1 in city 2 with 10 elements and force 20
001:40 red iceman 1 fought back against blue dragon 2 in city 2
001:40 blue dragon 2 was killed in city 2
001:40 red iceman 1 earned 10 elements for his headquarter
001:50 21 elements in red headquarter
001:50 49 elements in blue headquarter
002:00 blue ninja 3 born
002:10 red lion 2 marched to city 2 with 100 elements and force 50
002:10 blue ninja 3 marched to city 2 with 20 elements and force 50
002:10 red iceman 1 reached blue headquarter with 29 elements and force 70
002:40 blue ninja 3 attacked red lion 2 in city 2 with 20 elements and force 50
002:40 red lion 2 fought back against blue ninja 3 in city 2
002:40 blue ninja 3 was killed in city 2
002:40 red lion 2 earned 10 elements for his headquarter
002:40 red flag raised in city 2
002:50 23 elements in red headquarter
002:50 29 elements in blue headquarter
003:10 red lion 2 reached blue headquarter with 58 elements and force 50
003:10 blue headquarter was taken
Case:2
000:00 red iceman 1 born
000:00 blue lion 1 born
000:10 red iceman 1 marched to city 1 with 20 elements and force 20
000:10 blue lion 1 marched to city 1 with 20 elements and force 20
000:40 red iceman 1 attacked blue lion 1 in city 1 with 20 elements and force 20
000:40 blue lion 1 was killed in city 1
000:40 red iceman 1 earned 10 elements for his headquarter
000:50 22 elements in red headquarter
000:50 20 elements in blue headquarter
001:00 red lion 2 born
001:00 blue dragon 2 born
001:10 red lion 2 marched to city 1 with 20 elements and force 20
001:10 blue dragon 2 marched to city 1 with 20 elements and force 20
001:10 red iceman 1 reached blue headquarter with 39 elements and force 40
001:40 red lion 2 attacked blue dragon 2 in city 1 with 20 elements and force 20
001:40 blue dragon 2 was killed in city 1
001:40 red lion 2 earned 10 elements for his headquarter
001:40 red flag raised in city 1
001:50 12 elements in red headquarter
001:50 0 elements in blue headquarter
002:10 red lion 2 reached blue headquarter with 20 elements and force 20
002:10 blue headquarter was taken

代码如下:核心思想是 没有核心思想

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
#include <bits/stdc++.h>
using namespace std;

#define PRINT_DEBUG_TIME cout<<"当前时间 Round "<<Round<<" g_time "<<g_time%60<<"分"<<endl

int n, M, N, T, M_red, M_blue; // 每个司令部一开始有 M个生命元( 1 <= M <= 1000); 两个司令部之间一共有N个城市( 1 <= N <= 20 );游戏时间总共为 0 <= T <= 1000
string w_name[10] = {"dragon", "ninja", "iceman", "lion", "wolf"};
int w_life[10] = {0}; // 依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于100
int w_attack[10] = {0}; // 依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于100
int Round = 0; // 辅助参数,记录第几轮
int g_time = 0;
int w_red_seq[] = {2, 3, 4, 1, 0}; // 红方武士的制造顺序
int w_blue_seq[] = {3, 0, 1, 2, 4}; // 红方武士的制造顺序
int red_base_num = 0, blue_base_num = 0; // 红蓝基地初始敌方人员数量
int game_over = 0; // 1:红方胜 2:蓝方胜

struct City
{
int flag; // 0为空,1为红旗,2为蓝旗
int element; // 该城市的生命元
int index_red; // city中红方warrier的编号, -1:表示没有
int index_blue; // city中蓝方warrier的编号, -1:表示没有
int last_winner; // 存储上一场的胜方。若无旗,则连续两次获胜插旗;若对方旗,则两次后换旗 0:没有; 1:red;2:blue
};
struct City city[50]; // 初始化城市

struct Warrier
{
bool is_dead; // 是否已死
string name;
int life; // 生命值
int attack; // 攻击值
int city; // 所在城市 -1:表示敌方基地
int kill_no;
} ;
struct Warrier w_red[50], w_blue[50]; // 各定义50个
int i_w_red = 0, i_w_blue = 0; // 记载red、blue的已生成武士数量。均初始为0



/* 每小时的 00 分,
1.双方的司令部中各有一个武士降生。
红方顺序 iceman、lion、wolf、ninja、dragon ;
蓝方顺序 lion、dragon、ninja、iceman、wolf 。
2.制造武士需要生命元
2.1 制造一个初始生命值为 m 的武士,司令部中的生命元就要减少 m 个
2.2 如果司令部中的生命元不足,那么司令部就等待,直到获得足够生命元后的第一个整点,才制造该武士。
例如,在2:00,红方司令部本该制造一个 wolf ,如果此时生命元不足,那么就会等待,直到生命元足够后的下一个整点,才制造一个 wolf
*/
int born()
{
if( M_red >= w_life[ w_red_seq[Round%5] ] )
{
M_red -= w_life[ w_red_seq[Round%5] ]; // 总部生命元减少
w_red[i_w_red] = {false, w_name[w_red_seq[Round%5]], w_life[ w_red_seq[Round%5] ], w_attack[ w_red_seq[Round%5] ], 0, 0}; // 初始化red武士参数
cout << setw(3) << setfill('0') << Round << ":00" << " red " << w_red[i_w_red].name << " " << i_w_red + 1 << " born " << endl;
i_w_red ++;
}
if( M_blue >= w_life[ w_blue_seq[Round%5] ] )
{
M_blue -= w_life[ w_blue_seq[Round%5] ];
w_blue[i_w_blue] = {false, w_name [w_blue_seq[Round%5]], w_life[ w_blue_seq[Round%5] ], w_attack[ w_blue_seq[Round%5] ], N+1, 0}; // 初始化blue武士参数
cout << setw(3) << setfill('0') << Round << ":00" << " blue " << w_blue[i_w_blue].name << " " << i_w_blue + 1 << " born " << endl;
i_w_blue ++;
}
return 0;
}

int Time_00()
{
// cout<< "Round " << Round <<endl;
// PRINT_DEBUG_TIME;
born();
g_time += 10;
return 0;
}



// 如果是iceman,则每前进两步,在第2步完成的时候,生命值会减少9,攻击力会增加20。但是若生命值减9后会小于等于0,则生命值不减9,而是变为1
int iceman_move(int color, int index)
{
if(color == 1) // 红方 iceman
{
if ( (w_red[index].city % 2) == 0 ) // 只要是偶数城市,就执行一次
{
w_red[index].attack += 20;
if ( w_red[index].life > 9 )
{
w_red[index].life -= 9;
}
else
{
w_red[index].life = 1;
}
}
}
else if(color == 2) // 蓝方 iceman
{
if ( ( (N + 1 - w_blue[index].city) % 2) == 0 ) // 蓝方初始为N+1,故减去city编号即为步数。只要是偶数步数,就执行一次
{
w_blue[index].attack += 20;
if ( w_blue[index].life > 9 )
{
w_blue[index].life -= 9;
}
else
{
w_blue[index].life = 1;
}
}
}

return 0;
}

/* 每小时的 10 分,
1.所有的武士朝敌人司令部方向前进一步。
即从 ①己方司令部走到相邻城市;或 ②从一个城市走到下一个城市;或 ③从和敌军司令部相邻的城市到达敌军司令部
*/
int move()
{
// red 移动
for( int i = 0; i < i_w_red; i++ )
{
city[ w_red[i].city ].index_red = -1; // 原 warrior 所在城市的编号恢复初始值
w_red[i].city ++;
if ( w_red[i].name == "iceman" )
{
iceman_move(1, i);
}

cout << setw(3) << setfill('0') << Round << ":10" << " red " << w_red[i].name << " " << i+1 << " marched to city " << w_red[i].city << " with " << w_red[i].life << " elements and force " << w_red[i].attack << endl;
if (w_red[i].city <= N )
{
city[ w_red[i].city ].index_red = i; // 更新 新城市的红方warrior编号
}
else if ( w_red[i].city > N )
{
w_red[i].city = -1;
blue_base_num ++;
if (blue_base_num == 2 )
{
cout << setw(3) << setfill('0') << Round << ":10" << " blue headquarter was taken" << endl;
game_over = 1; // 红方胜
return 0;
}
else
{
cout << setw(3) << setfill('0') << Round << ":10" << " red " << w_red[i].name << " " << i+1 << " reached blue headquarter with " << w_red[i].life << " elements and force " << w_red[i].attack << endl;
}
}
}
// blue 移动
for( int i = 0; i < i_w_blue; i++ )
{
city[ w_blue[i].city ].index_blue = -1; // 原 warrior 所在城市的编号恢复初始值
w_blue[i].city --;
if ( w_blue[i].name == "iceman" )
{
iceman_move(2, i);
}
cout << setw(3) << setfill('0') << Round << ":10" << " blue " << w_blue[i].name << " " << i+1 << " marched to city " << w_blue[i].city << " with " << w_blue[i].life << " elements and force " << w_blue[i].attack << endl;
if (w_blue[i].city >= 1 )
{
city[ w_blue[i].city ].index_blue = i; // 更新 新城市的蓝方warrior编号
}
else if ( w_blue[i].city < 1)
{
w_blue[i].city = -1;
red_base_num ++;
if (red_base_num ==2 )
{
cout << setw(3) << setfill('0') << Round << ":10" << " red headquarter was taken" << endl;
game_over = 2; // 蓝方胜
return 0;
}
else
{
cout << setw(3) << setfill('0') << Round << ":10" << " blue " << w_blue[i].name << " " << i+1 << " reached red headquarter with " << w_blue[i].life << " elements and force " << w_blue[i].attack << endl;
}
}
}
return 0;
}

int Time_10()
{
// PRINT_DEBUG_TIME;
move(); // 移动
g_time += 10;
return 0;
}


/* 每小时的 20 分触发事件
1.每个城市产出10个生命元。生命元留在城市(直到被武士取走--第30分钟事件)
*/
int Time_20()
{
// PRINT_DEBUG_TIME;
// 更新城市生命元
for( int i = 1; i <= N; i++ )
{
city[i].element += 10;
// cout << "city " << i << "'s new element is " << city[i].element << endl;
}
g_time += 10;
return 0;
}


/* 每小时的 30 分触发事件
1.如果某个城市中只有一个武士,那么该武士取走该城市中的所有生命元,并立即将这些生命元传送到其所属的司令部
*/
int Get_element()
{
for (int i = 1; i <= N; i++)
{
if ( city[i].element !=0 )
{ // 如果city中仅有一个红方warrior
if ( (city[i].index_red != -1) && (city[i].index_blue == -1) )
{
M_red += city[i].element;
cout << setw(3) << setfill('0') << Round << ":30" << " red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " earned " << city[i].element << " elements for his headquarter " << endl;
city[i].element = 0;
} // 如果city中仅有一个蓝方warrior
else if ( (city[i].index_red == -1) && (city[i].index_blue != -1) )
{
M_blue += city[i].element;
cout << setw(3) << setfill('0') << Round << ":30" << " blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " earned " << city[i].element << " elements for his headquarter " << endl;
city[i].element = 0;
}
}
}

return 0;
}

int Time_30()
{
// PRINT_DEBUG_TIME;
Get_element();
g_time += 10;
return 0;
}


/* 每小时的 40 分触发事件
1.在有两个武士的城市,会发生战斗
*/
// 1.基地奖励武士;2.收回该城市的生命元
int win_award( int color, int index )
{
if ( color == 1)
{ // 如果红方 基地生命元足够
if ( M_red >= 8 )
{
w_red[ index ].life += 8;
M_red -= 8; // 基地先赏赐 8个生命元
M_red += city[w_red[ index ].city].element; // 再收回该城市的所有生命元
cout << setw(3) << setfill('0') << Round << ":40" << " red " << w_red[ index ].name << " " << index + 1 << " earned " << city[w_red[ index ].city].element << " elements for his headquarter " << endl;
city[w_red[ index ].city].element = 0;
}
}
else if ( color == 2)
{ // 如果蓝方 基地生命元足够
if ( M_blue >= 8 )
{
w_blue[ index ].life += 8;
M_blue -= 8;
M_blue += city[w_blue[ index ].city].element; // 再收回该城市的所有生命元
cout << setw(3) << setfill('0') << Round << ":40" << " blue " << w_blue[ index ].name << " " << index + 1 << " earned " << city[w_blue[ index ].city].element << " elements for his headquarter " << endl;
city[w_blue[ index ].city].element = 0;
}
}
return 0;
}

/* wolf 通过主动攻击杀死敌人的次数达到偶数的时刻(次数从1开始算),在战斗完成后,该 wolf 生命值和攻击力都增加1倍。如果其杀死的敌人是lion,则
攻击力和生命值先加倍,然后才吸取lion的生命值。获取总部的生命元奖励,发生在加倍之后。只有在主动攻击杀死敌人时才能有加倍的事情,反击杀死敌
人则不不会发生加倍。
*/
int check_wolf(int color, int i)
{
if( color == 1 ) // 红方牺牲
{
if( w_blue[ city[i].index_blue ].name == "wolf" ) // 如果蓝方活的是 wolf,则生命和攻击力翻倍
{
w_blue[ city[i].index_blue ].attack += w_blue[ city[i].index_blue ].attack;
w_blue[ city[i].index_blue ].life += w_blue[ city[i].index_blue ].life;
}
}
else if( color == 2 ) // 蓝方牺牲
{
if( w_red[ city[i].index_red ].name == "wolf" ) // 如果蓝方活的是 wolf,则生命和攻击力翻倍
{
w_red[ city[i].index_red ].attack += w_red[ city[i].index_red ].attack;
w_red[ city[i].index_red ].life += w_red[ city[i].index_red ].life;
}
}
return 0;
}

/*
1.city[i].flag = 1:red旗;2:blue旗
2.city[i].last_winner = 1:上一局红方胜;2,上一局蓝方胜
传入的参数 i 为 city 索引
*/
int check_flag(int color, int i)
{
if ( city[i].flag == 0 ) // 如果无旗
{
if ( color == 1 ) // 如果败的是红方 (即胜的是蓝方)
{
if ( city[i].last_winner == 2 ) // 如果上一局胜者是 blue
{
city[i].flag = 2;
cout << setw(3) << setfill('0') << Round << ":40" << " blue flag raiesd in city " << i << endl;
}
else
{
city[i].last_winner = 2;
}
}
else if ( color == 2 ) // 如果败的是蓝方(即胜的是红方)
{
if ( city[i].last_winner == 1) // 如果上一局胜者是红方
{
city[i].flag = 1;
cout << setw(3) << setfill('0') << Round << ":40" << " red flag raiesd in city " << i << endl;
}
else
{
city[i].last_winner = 1;
}
}
}
else if ( city[i].flag == 1 ) // 如果当前是 red 旗
{
if ( color == 1 ) // 如果败的是 red 方 (即胜的是蓝方)
{
if ( city[i].last_winner == 2 ) // 如果上一局胜者是 blue
{
city[i].flag = 2;
cout << setw(3) << setfill('0') << Round << ":40" << " blue flag raiesd in city " << i << endl;
}
else
{
city[i].last_winner = 2;
}
}
else if ( color == 2 ) // 如果败的是 blue 方(即胜的是 red方)
{
city[i].last_winner = 1;
}
}
else if ( city[i].flag == 2 ) // 如果当前是 blue 旗
{
if ( color == 2 ) // 如果败的是 blue 方 (即胜的是 red方)
{
if ( city[i].last_winner == 1 ) // 如果上一局胜者是 red
{
city[i].flag = 1;
cout << setw(3) << setfill('0') << Round << ":40" << " red flag raiesd in city " << i << endl;
}
else
{
city[i].last_winner = 1;
}
}
else if ( color == 1 ) // 如果败的是 red 方(即胜的是 blue 方)
{
city[i].last_winner = 2;
}
}

}

/* 武士牺牲
1. 如果牺牲的是 lion ,则其战斗前的生命值就会转移到对手身上
2. 如果活着的是 dragon,发出欢呼
*/
int warrior_dead(int color, int i)
{
if( color == 1 ) // 红方牺牲
{
if( w_red[ city[i].index_red ].name == "lion" ) // 1. 如果牺牲的是 lion ,则其战斗前的生命值就会转移到对手身上
{
w_blue[ city[i].index_blue ].life += w_red[ city[i].index_red ].life;
}
w_red[ city[i].index_red ].life = 0;
w_red[ city[i].index_red ].is_dead = true;
// 输出红方牺牲字符串
cout << setw(3) << setfill('0') << Round << ":40" << " red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " was killed in city " << i << endl;
city[i].index_red = -1;


if( w_blue[ city[i].index_blue ].name == "dragon" ) // 如果蓝方活的是dragon,发出欢呼
{
cout << setw(3) << setfill('0') << Round << ":40" << " blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " yelled in city " << i << endl;
}

check_flag(1, i); // 检查是否插旗或者换旗
}
else if ( color == 2 ) // 蓝方牺牲
{
if( w_blue[ city[i].index_blue ].name == "lion" ) // 1. 如果牺牲的是 lion ,则其战斗前的生命值就会转移到对手身上
{
w_red[ city[i].index_red ].life += w_blue[ city[i].index_blue ].life;
}
w_blue[ city[i].index_blue ].life = 0;
w_blue[ city[i].index_blue ].is_dead = true;
// 输出蓝方牺牲字符串
cout << setw(3) << setfill('0') << Round << ":40" << " blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " was killed in city " << i << endl;
city[i].index_blue = -1;


if( w_red[ city[i].index_red ].name == "dragon" ) // 如果红方活的是dragon,发出欢呼
{
cout << setw(3) << setfill('0') << Round << ":40" << " red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " yelled in city " << i << endl;
}

check_flag(2, i); // 检查是否插旗或者换旗
}

return 0;
}

// 发生一轮战斗
int fight()
{
for (int i = 1; i <= N; i++)
{
// 如果该 city 中红蓝 warrior 均存在
if( (city[i].index_red != -1) && (city[i].index_blue != -1) )
{ // 如果该城市插红旗,或虽无旗城市但是 index 为基数 ,则红方先发起进攻
if ( (city[i].flag == 1) || ( (city[i].flag == 0) && (i%2 == 1)) )
{
cout << setw(3) << setfill('0') << Round << ":40" << " red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " attacked blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " in city " << i << " with " << w_red[ city[i].index_red ].life << " elements and force " << w_red[ city[i].index_red ].attack << endl;
if ( w_blue[ city[i].index_blue ].life > w_red[ city[i].index_red ].attack )
{
w_blue[ city[i].index_blue ].life -= w_red[ city[i].index_red ].attack; // 若蓝方没挂,则蓝方 life -- , 然后发动进攻
if( w_blue[ city[i].index_blue ].name == "ninja" ) // 如果蓝方是ninja, 则不反击
{
return 0;
}

// 蓝方反击文字
cout << setw(3) << setfill('0') << Round << ":40" << " blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " fought back against red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " in city " << i << endl;


if ( w_red[ city[i].index_red ].life > ( w_blue[ city[i].index_blue ].attack / 2 ) )
{
w_red[ city[i].index_red ].life -= (w_blue[ city[i].index_blue ].attack / 2); // 若红方没挂,则红方 life --
}
else
{
w_blue[ city[i].index_blue ].kill_no ++;
warrior_dead(1, i); // 红方阵亡
win_award(2, city[i].index_blue); // 奖励蓝方,2示蓝方
}
}
else
{
w_red[ city[i].index_red ].kill_no ++;
check_wolf(2, i); // 主动攻击获胜,先检查获胜的是否wolf,如果是,先翻倍
warrior_dead(2, i); // 蓝方阵亡
win_award(1, city[i].index_red); // 奖励红方,1表示红方
}
} // 插蓝旗,或虽无旗但城市index为偶数,则蓝方先进攻
else if ( (city[i].flag == 2) || ( (city[i].flag == 0) && (i%2 == 0)) )
{
cout << setw(3) << setfill('0') << Round << ":40" << " blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " attacked red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " in city " << i << " with " << w_blue[ city[i].index_blue ].life << " elements and force " << w_blue[ city[i].index_blue ].attack << endl;
if ( w_red[ city[i].index_blue ].life > w_blue[ city[i].index_red ].attack )
{
w_red[ city[i].index_blue ].life -= w_blue[ city[i].index_red ].attack; // 若红方没挂,则红方 life -- , 然后发动进攻
if( w_red[ city[i].index_red ].name == "ninja" ) // 如果红方是ninja, 则不反击
{
return 0;
}

// 红方反击文字
cout << setw(3) << setfill('0') << Round << ":40" << " red " << w_red[ city[i].index_red ].name << " " << city[i].index_red + 1 << " fought back against blue " << w_blue[ city[i].index_blue ].name << " " << city[i].index_blue + 1 << " in city " << i << endl;

if ( w_blue[ city[i].index_red ].life > ( w_red[ city[i].index_blue ].attack / 2 ) )
{
w_blue[ city[i].index_red ].life -= (w_red[ city[i].index_blue ].attack / 2); // 若红方没挂,则红方 life --
}
else
{
w_red[ city[i].index_red ].kill_no ++;
warrior_dead(2, i); // 蓝方阵亡
win_award(1, city[i].index_red); // 奖励红方,1示红方
}
}
else
{
w_blue[ city[i].index_blue ].kill_no ++;
check_wolf(1, i); // 主动攻击获胜,先检查获胜的是否wolf,如果是,先翻倍
warrior_dead(1, i); // 红方阵亡
win_award(2, city[i].index_blue); // 奖励蓝方,2表示蓝方
}
}

}
}
}

int Time_40()
{
// PRINT_DEBUG_TIME;
fight();
g_time += 10;
return 0;
}


/* 每小时的 50 分触发事件
1.司令部报告它拥有的生命元数量
*/
int Time_50()
{
// PRINT_DEBUG_TIME;
cout << setw(3) << setfill('0') << Round << ":50 " << M_red << " elements in red headquarter " << endl;
cout << setw(3) << setfill('0') << Round << ":50 " << M_blue << " elements in blue headquarter " << endl;

g_time += 10;
return 0;
}


int main()
{
int i;

cin >> n; // 获取几组数据

for(int k = 1; k <= n; k++)
{

// 每个司令部一开始有 M个生命元( 1 <= M <= 1000); 两个司令部之间一共有N个城市( 1 <= N <= 20 );游戏时间总共为 0 <= T <= 1000
cin >> M >> N >> T; //

M_red = M; // 初始化 red 基地生命元
M_blue = M; // 初始化 blue 基地生命元

// 初始化城市
for( i = 0; i <= N+1; i++ )
{
city[i].flag = 0;
city[i].element = 0;
city[i].index_red = -1;
city[i].index_blue = -1;
city[i].last_winner = 0;
}

// 第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于100
for( i = 0; i < 5; i++ )
{
cin >> w_life[i];
}

// 第三行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的攻击力。它们都大于0小于等于100
for( i = 0; i < 5; i++ )
{
cin >> w_attack[i];
}
cout << "Case " << k << ":" << endl;

for( g_time = 0; g_time < T; )
{
Time_00();
Time_10();
if( game_over == 1 || game_over == 2 )
{
game_over = 0;
red_base_num = 0;
blue_base_num = 0;
Round = 0;
i_w_red = 0;
i_w_blue = 0;
break;
}
Time_20();
Time_30();
Time_40();
Time_50();
Round++; // 一轮完成,开始下一轮
}
}

return 0;
}