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; string w_name[10] = {"dragon", "ninja", "iceman", "lion", "wolf"}; int w_life[10] = {0}; int w_attack[10] = {0}; 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;
struct City { int flag; int element; int index_red; int index_blue; int last_winner; }; struct City city[50];
struct Warrier { bool is_dead; string name; int life; int attack; int city; int kill_no; } ; struct Warrier w_red[50], w_blue[50]; int i_w_red = 0, i_w_blue = 0;
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}; 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}; 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() {
born(); g_time += 10; return 0; }
int iceman_move(int color, int index) { if(color == 1) { 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) { if ( ( (N + 1 - w_blue[index].city) % 2) == 0 ) { w_blue[index].attack += 20; if ( w_blue[index].life > 9 ) { w_blue[index].life -= 9; } else { w_blue[index].life = 1; } } } return 0; }
int move() { for( int i = 0; i < i_w_red; i++ ) { city[ w_red[i].city ].index_red = -1; 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; } 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; } } } for( int i = 0; i < i_w_blue; i++ ) { city[ w_blue[i].city ].index_blue = -1; 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; } 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() {
move(); g_time += 10; return 0; }
int Time_20() {
for( int i = 1; i <= N; i++ ) { city[i].element += 10;
} g_time += 10; return 0; }
int Get_element() { for (int i = 1; i <= N; i++) { if ( city[i].element !=0 ) { 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; } 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() {
Get_element(); g_time += 10; return 0; }
int win_award( int color, int index ) { if ( color == 1) { if ( M_red >= 8 ) { w_red[ index ].life += 8; M_red -= 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; }
int check_wolf(int color, int i) { if( color == 1 ) { if( w_blue[ city[i].index_blue ].name == "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" ) { 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; }
int check_flag(int color, int i) { if ( city[i].flag == 0 ) { if ( color == 1 ) { if ( city[i].last_winner == 2 ) { 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 ) { if ( color == 1 ) { if ( city[i].last_winner == 2 ) { 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 ) { city[i].last_winner = 1; } } else if ( city[i].flag == 2 ) { 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 ( color == 1 ) { city[i].last_winner = 2; } } }
int warrior_dead(int color, int i) { if( color == 1 ) { if( w_red[ city[i].index_red ].name == "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" ) { 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" ) { 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" ) { 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++) { if( (city[i].index_red != -1) && (city[i].index_blue != -1) ) { 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; if( w_blue[ city[i].index_blue ].name == "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); } else { w_blue[ city[i].index_blue ].kill_no ++; warrior_dead(1, i); win_award(2, city[i].index_blue); } } else { w_red[ city[i].index_red ].kill_no ++; check_wolf(2, i); warrior_dead(2, i); win_award(1, city[i].index_red); } } 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; if( w_red[ city[i].index_red ].name == "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); } else { w_red[ city[i].index_red ].kill_no ++; warrior_dead(2, i); win_award(1, city[i].index_red); } } else { w_blue[ city[i].index_blue ].kill_no ++; check_wolf(1, i); warrior_dead(1, i); win_award(2, city[i].index_blue); } } } } }
int Time_40() {
fight(); g_time += 10; return 0; }
int Time_50() {
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++) { cin >> M >> N >> T; M_red = M; M_blue = M; 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; } for( i = 0; i < 5; i++ ) { cin >> w_life[i]; } 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; }
|