Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1882 | Accepted: 448 |
Description
魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 …. N ( N <= 20)。
两军的司令部都会制造武士。武士一共有 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) 武士降生
输出样例: 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号事件
虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。
Input
每组测试数据共三行。第一行,三个整数 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
Output
接下来按恰当的顺序和格式输出到时间T为止发生的所有事件。每个事件都以事件发生的时间开头,时间格式是「时: 分」,「时」有三位,「分」有两位。
Sample Input
1 2 3 4 5 6 7 |
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 |
Sample Output
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 |
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 |
Source
思路
做完这道神级模拟题目过后,禁不住仰天长啸一句——interesting。。。
差不多是自己目前为止写过的最长单文件代码了。。。
这道题目最好还是用C++的类,用C的struct的话。。。想都不敢想。。。
至于具体的算法,关键在于每一次前进和检查处理都以城市为单位,一开始我是以战士为单位,果断TLE了一波然后几乎全部推倒重写了一遍,另外就是题目的每一个字都要认真读,每一个字都是关键点,随便看漏了哪个地方逻辑关系不符合题意轻松WA好几个小时。。。
附上poj讨论区的数据, 这个题没数据debug的话还是有一点痛苦的。。。
代码
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 |
/* * File Name: poj3760.cpp * Author: razrLeLe * Mail: razrlele@gmail.com */ #define LOCAL #include <vector> #include <set> #include <deque> #include <queue> #include <algorithm> #include <functional> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <string> #include <cstring> #include <string.h> #include <map> #include <cctype> #include <list> #include <stack> #include <iomanip> typedef long long ll; using namespace std; #define INF 0x3f3f3f3f static string wname[5] = { "dragon", "ninja", "iceman", "lion", "wolf" }; static int order[2][5] = { { 2, 3, 4, 1, 0 }, { 3, 0, 1, 2, 4 } }; int IniStrength[5]; // 0 dragon, 1 ninja, 2 iceman, 3 lion, 4 wolf int IniPower[5]; int M, N, T; int nowtime; int arrived[2]; void printnowtime() { int hours = nowtime / 60, minutes = nowtime % 60; int bits = 1; int tmpt = hours; while (tmpt / 10) { bits++; tmpt /= 10; } for (int i = 0; i < 3 - bits; i++) printf("0"); printf("%d:", hours); if (minutes / 10) printf("%d", minutes); else printf("0%d", minutes); cout << " "; return; } class warrior { public: int side; int warriorId; int place; int power; int strength; int id; bool win; int earned; int step; bool moved; bool arrivedHead; // to check whether arrived headquarter string color; warrior(int i, int wId, int dir) : id(i) , warriorId(wId) , strength(IniStrength[wId]) , power(IniPower[wId]) , side(dir) { arrivedHead = false; earned = 0; step = 0; if (dir) { color = "blue"; place = N + 1; } else { color = "red"; place = 0; } moved = false; printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " born" << endl; } virtual void Attack(warrior* pW) {} virtual int Hurted(int pW) {} virtual void FightBack(warrior* pW) {} void addStep() { step++; if (step % 2 == 0) { if (strength != 1) { if (strength > 9) strength -= 9; else strength = 1; } power += 20; //It looks like only increase when strength decreased } } void killed(); void move(); void earn(); }; class city { public: int win[2]; bool Here[2]; int belong; // if 0 belongs to red else belongs to blue -1 belongs to no size int elements; warrior* Cwarrior[2]; } C[25]; bool judgeWhoFirst(int side, int cityId) { //judge whether to attack first if (C[cityId].belong == side || (C[cityId].belong == -1 && cityId % 2 == 1 - side)) return true; return false; } void warrior::earn() { //only win to earn earned = C[place].elements; C[place].elements = 0; printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " earned " << earned << " elements for his headquarter" << endl; C[place].win[side]++; C[place].win[1 - side] = 0; //failed if (C[place].win[side] == 2) { if (C[place].belong != side) { printnowtime(); cout << color << " flag raised in city " << place << endl; C[place].belong = side; } } } void warrior::killed() { cout << color << " " << wname[warriorId] << " " << id << " was killed in city " << place << endl; } void warrior::move() { if (moved) return; if ((place == 0 && side == 1) || (place == N + 1 && side == 0)) return; C[place].Here[side] = false; moved = true; if (warriorId == 2) //iceman can increase his power and decrease his strength { addStep(); } if (side) { place--; } else place++; C[place].Here[side] = true; C[place].Cwarrior[side] = this; if (place == N + 1) { arrived[1]++; } else if (place == 0) { arrived[0]++; } } class dragon : public warrior { private: public: dragon(int id, int p) : warrior(id, 0, p) { } virtual void Attack(warrior* pW) { // only use sword printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " attacked " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << place << " with " << strength << " elements and force " << power << endl; strength += pW->Hurted(power); if (pW->strength > 0) { pW->FightBack(this); } if (strength > 0) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " yelled in city " << place << endl; } //enemy died , win and earn if (pW->strength <= 0) { win = true; earn(); } } virtual int Hurted(int pW) { strength -= pW; if (strength <= 0) { printnowtime(); killed(); } return 0; } virtual void FightBack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " fought back against " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << pW->place << endl; strength += pW->Hurted(power / 2); if (pW->strength <= 0) { win = true; earn(); } } }; class ninja : public warrior { private: public: ninja(int wid, int p) : warrior(wid, 1, p) { } virtual void Attack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " attacked " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << place << " with " << strength << " elements and force " << power << endl; strength += pW->Hurted(power); if (pW->strength <= 0) { win = true; earn(); } else pW->FightBack(this); } virtual int Hurted(int pW) { strength -= pW; if (strength <= 0) { printnowtime(); killed(); } return 0; } virtual void FightBack(warrior* pW) { ; } //ninja never fight back }; class iceman : public warrior { private: public: iceman(int id, int p) : warrior(id, 2, p) { step = 0; } virtual void Attack(warrior* pW) { // only use sword if (pW->strength <= 0) { win = true; earn(); return; } printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " attacked " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << place << " with " << strength << " elements and force " << power << endl; strength += pW->Hurted(power); if (pW->strength <= 0) { win = true; earn(); } else pW->FightBack(this); } virtual int Hurted(int pW) { strength -= pW; if (strength <= 0) { printnowtime(); killed(); } return 0; } virtual void FightBack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " fought back against " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << pW->place << endl; strength += pW->Hurted(power / 2); if (pW->strength <= 0) { win = true; earn(); } } }; class lion : public warrior { private: public: lion(int id, int p) : warrior(id, 3, p) { } virtual void Attack(warrior* pW) { if (pW->strength <= 0) { win = true; earn(); return; } printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " attacked " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << place << " with " << strength << " elements and force " << power << endl; strength += pW->Hurted(power); if (pW->strength <= 0) { win = true; earn(); } else { pW->FightBack(this); } } virtual int Hurted(int pW) { int tmp = strength; strength -= pW; if (strength <= 0) //if lion dies, it will return life { printnowtime(); killed(); return tmp; } return 0; } virtual void FightBack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " fought back against " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << pW->place << endl; strength += pW->Hurted(power / 2); if (pW->strength <= 0) { earn(); win = true; } } }; class wolf : public warrior { private: int killfirst; public: wolf(int id, int p) : warrior(id, 4, p) { killfirst = 0; } virtual void Attack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " attacked " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << place << " with " << strength << " elements and force " << power << endl; int gainFromLion = pW->Hurted(power); if (pW->strength <= 0) { killfirst++; if (killfirst % 2 == 0) { strength *= 2; power *= 2; } strength += gainFromLion; win = true; earn(); } else pW->FightBack(this); } virtual int Hurted(int pW) { strength -= pW; if (strength <= 0) { printnowtime(); killed(); } return 0; } virtual void FightBack(warrior* pW) { printnowtime(); cout << color << " " << wname[warriorId] << " " << id << " fought back against " << pW->color << " " << wname[pW->warriorId] << " " << pW->id << " in city " << pW->place << endl; strength += pW->Hurted(power / 2); if (pW->strength <= 0) { earn(); win = true; } } }; class headquarter { private: string color; int wnum[5]; int count; public: int life; headquarter() { } headquarter(string side, int IniLife) : color(side) , life(IniLife) { memset(wnum, 0, sizeof(wnum)); count = 0; } void consume(int n) { life -= n; } int getLife() { return life; } int getWnum(int i) { return wnum[i]; } void addWnum(int i, int p) //red 0 blue 1 { wnum[i]++; count++; int head; if (p == 0) head = 0; else head = N + 1; C[head].Here[p] = true; switch (i) { case 0: C[head].Cwarrior[p] = new dragon(count, p); break; case 1: C[head].Cwarrior[p] = new ninja(count, p); break; case 2: C[head].Cwarrior[p] = new iceman(count, p); break; case 3: C[head].Cwarrior[p] = new lion(count, p); break; case 4: C[head].Cwarrior[p] = new wolf(count, p); break; } } string getColor() { return color; } void report(); } * H[2]; void moveForward() { for (int i = 1; i <= N + 1; i++) { if (C[i].Here[1]) { C[i].Cwarrior[1]->move(); } } for (int i = N; i >= 0; i--) { if (C[i].Here[0]) { C[i].Cwarrior[0]->move(); } } } void reset() //reset win and moved flag { for (int i = 1; i <= N; i++) for (int j = 0; j < 2; j++) if (C[i].Here[j]) { C[i].Cwarrior[j]->win = false; C[i].Cwarrior[j]->moved = false; } } void clean() { for (int i = 1; i <= N; i++) for (int j = 0; j <= 2; j++) if (C[i].Here[j]) if (C[i].Cwarrior[j]->strength <= 0) { C[i].Here[j] = false; } } void award() { warrior *tmp0, *tmp1; for (int i = 1, j = N; i <= N, j >= 1; i++, j--) { if (C[i].Here[1]) { tmp1 = C[i].Cwarrior[1]; if (tmp1->win && H[1]->life >= 8) { tmp1->strength += 8; H[1]->life -= 8; } } if (C[j].Here[0]) { tmp0 = C[j].Cwarrior[0]; if (tmp0->win && H[0]->life >= 8) { //cout << "has award :" << tmp0->color // << " " << wname[tmp0->warriorId] << endl; tmp0->strength += 8; H[0]->life -= 8; } } } //award first then take elements for (int i = 1; i <= N; i++) { for (int j = 0; j < 2; j++) if (C[i].Here[j]) { if (C[i].Cwarrior[j]->win) H[j]->life += C[i].Cwarrior[j]->earned; C[i].Cwarrior[j]->earned = 0; } } } void attackEnemy() { for (int i = 1; i <= N; i++) { if (C[i].Here[0] && C[i].Here[1]) { warrior* tmp0 = C[i].Cwarrior[0]; warrior* tmp1 = C[i].Cwarrior[1]; if (judgeWhoFirst(tmp0->side, i) && tmp0->strength > 0) tmp0->Attack(tmp1); else if (tmp1->strength > 0) tmp1->Attack(tmp0); // tmp1 attack first or tmp0 killed by arrow else if (tmp0->strength > 0 && tmp1->strength <= 0) tmp0->Attack(tmp1); //tmp1 killed by arrow } } } void takeElements() { for (int i = 1; i <= N; i++) { if ((C[i].Here[0] ^ C[i].Here[1])) { //only one warrior is in the city warrior* tmp; if (C[i].Here[0]) tmp = C[i].Cwarrior[0]; else tmp = C[i].Cwarrior[1]; printnowtime(); cout << tmp->color << " " << wname[tmp->warriorId] << " " << tmp->id << " earned " << C[tmp->place].elements << " elements for his headquarter" << endl; // printnowtime(); // cout << tmp ->color << // " life from " << H[tmp->side ]->life; H[tmp->side]->life += C[tmp->place].elements; //Here cout << " to " << H[tmp->side ]->life << endl; C[i].elements = 0; //its different from earn() } } } void headquarter::report() { printnowtime(); cout << life << " elements in " << color << " headquarter" << endl; } void born(headquarter* H, int id, int p) { H->consume(IniStrength[id]); H->addWnum(id, p); return; } void checkCity() { if (C[0].Here[1]) { printnowtime(); warrior* tmp = C[0].Cwarrior[1]; tmp->arrivedHead = true; cout << tmp->color << " " << wname[tmp->warriorId] << " " << tmp->id << " reached red headquarter with " << tmp->strength << " elements and force " << tmp->power << endl; C[0].Here[1] = false; } if (arrived[0] == 2) { printnowtime(); cout << "red headquarter was taken" << endl; } for (int i = 1; i <= N; i++) { for (int j = 0; j < 2; j++) if (C[i].Here[j]) { warrior* tmp = C[i].Cwarrior[j]; printnowtime(); cout << tmp->color << " " << wname[tmp->warriorId] << " " << tmp->id << " marched to city " << tmp->place << " with " << tmp->strength << " elements and force " << tmp->power << endl; } } if (C[N + 1].Here[0]) { printnowtime(); warrior* tmp = C[N + 1].Cwarrior[0]; tmp->arrivedHead = true; cout << tmp->color << " " << wname[tmp->warriorId] << " " << tmp->id << " reached blue headquarter with " << tmp->strength << " elements and force " << tmp->power << endl; C[N + 1].Here[0] = false; } if (arrived[1] == 2) { printnowtime(); cout << "blue headquarter was taken" << endl; } } int main() { #ifdef LOCAL freopen("/home/razrlele/build/in.txt", "r", stdin); freopen("/home/razrlele/build/out.txt", "w", stdout); #endif int caseN; cin >> caseN; for (int count = 1; count <= caseN; count++) { int index[2] = { 0, 0 }; cout << "Case:" << count << endl; cin >> M >> N >> T; for (int i = 0; i < 5; i++) { cin >> IniStrength[i]; } for (int i = 0; i < 5; i++) { cin >> IniPower[i]; } //initial input H[0] = new headquarter("red", M), H[1] = new headquarter("blue", M); arrived[0] = arrived[1] = 0; //initialize for city for (int i = 0; i <= N + 1; i++) { C[i].win[0] = C[i].win[1] = 0; C[i].Here[0] = C[i].Here[1] = false; C[i].belong = -1; C[i].Cwarrior[0] = C[i].Cwarrior[1] = NULL; C[i].elements = 0; } for (nowtime = 0; nowtime <= T; nowtime++) { // cout << nowtime << endl; if (nowtime % 60 == 20) // time to produce elements for (int i = 1; i <= N; i++) { C[i].elements += 10; } for (int i = 0; i < 2; i++) { if (nowtime % 60 == 0) { int nextW = order[i][index[i] % 5]; if (H[i]->getLife() >= IniStrength[nextW]) { born(H[i], nextW, i); index[i]++; } } else if (nowtime % 60 == 50) { H[i]->report(); } } if (nowtime % 60 == 10) { moveForward(); checkCity(); if (arrived[0] == 2 || arrived[1] == 2) break; } else if (nowtime % 60 == 30) { takeElements(); reset(); } else if (nowtime % 60 == 40) { attackEnemy(); award(); clean(); //clean the battle //flush battle record for (int i = 1; i <= N; i++) { if (C[i].Here[0] && C[i].Here[1]) { if (!C[i].Cwarrior[0]->win && !C[i].Cwarrior[1]->win) { C[i].win[0] = C[i].win[1] = 0; } } } } } } return 0; } |