魔獸世界之一:備戰cxsjsx.openjudge.com
-總時間限制: 1000ms
-內存限制: 65536kB
描述
魔獸世界的西面是紅魔軍的司令部,東面是藍魔軍的司令部。兩個司令部之間是依次排列的若干城市。
紅司令部,City 1,City 2,……,City n,藍司令部
兩軍的司令部都會製造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五種。每種武士都有編號、生命值、攻擊力這三種屬性。
雙方的武士編號都是從1開始計算。紅方製造出來的第n個武士,編號就是n。同樣,藍方製造出來的第n個武士,編號也是n。
武士在剛降生的時候有一個生命值。
在每個整點,雙方的司令部中各有一個武士降生。
紅方司令部按照iceman、lion、wolf、ninja、dragon的順序循環制造武士。
藍方司令部按照lion、dragon、ninja、iceman、wolf的順序循環制造武士。
製造武士需要生命元。
製造一個初始生命值爲m的武士,司令部中的生命元就要減少m個。
如果司令部中的生命元不足以製造某個按順序應該製造的武士,那麼司令部就試圖製造下一個。如果所有武士都不能製造了,則司令部停止製造武士。
給定一個時間,和雙方司令部的初始生命元數目,要求你將從0點0分開始到雙方司令部停止製造武士爲止的所有事件按順序輸出。
一共有兩種事件,其對應的輸出樣例如下:
1) 武士降生
輸出樣例: 004 blue lion 5 born with strength 5,2 lion in red headquarter
表示在4點整,編號爲5的藍魔lion武士降生,它降生時生命值爲5,降生後藍魔司令部裏共有2個lion武士。(爲簡單起見,不考慮單詞的複數形式)注意,每製造出一個新的武士,都要輸出此時司令部裏共有多少個該種武士。
2) 司令部停止製造武士
輸出樣例: 010 red headquarter stops making warriors
表示在10點整,紅方司令部停止製造武士
輸出事件時:
首先按時間順序輸出;
同一時間發生的事件,先輸出紅司令部的,再輸出藍司令部的。
輸入
第一行是一個整數,代表測試數據組數。
每組測試數據共兩行。
第一行:一個整數M。其含義爲, 每個司令部一開始都有M個生命元( 1 <= M <= 10000)。
第二行:五個整數,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它們都大於0小於等於10000。
輸出
對每組測試數據,要求輸出從0時0分開始,到雙方司令部都停止製造武士爲止的所有事件。
對每組測試數據,首先輸出"Case:n" n是測試數據的編號,從1開始 。
接下來按恰當的順序和格式輸出所有事件。每個事件都以事件發生的時間開頭,時間以小時爲單位,有三位。
樣例輸入
1
20
3 4 5 6 7
樣例輸出
Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors
題目分析
按照題目模擬操作,主要考察代碼能力
代碼實現
作爲競賽選手,我打了一些不像工程不像競賽的代碼,之後還有兩道擴展題需要做,希望我不會死
我的寫代碼過程:
1.按照題目隨心寫
2.Compile 更正語法錯誤
3.debug 把代碼改正確
然後我就第一次淺顯地體會到了如何維持代碼可擴展
#include<cstdio>
#include<cstring>
using std::strcpy;
const int M = 10000+10;
const char name_of_soldier[][7] = {"dragon", "ninja", "iceman", "lion", "wolf"};
int hp_of_soldier[6];
int time;
struct S{
char name[7];
int number,hp,rest;
S () {init();}
void init () {number = rest = 0;}
};
struct T{
char color[5];
int hp_of_headquarter;
S soldiers[6];
int number_of_new_soldier;
int next_soldier;
bool cant_make_soldier;
void init (bool red, int hp) {
next_soldier = number_of_new_soldier = cant_make_soldier = 0;
hp_of_headquarter = hp;
if (red) {
strcpy(color, "red");
int buf[5] = {2, 3, 4, 1, 0};
for (int i = 0; i < 5; i++) {
soldiers[i].init();
strcpy(soldiers[i].name, name_of_soldier[buf[i]]);
soldiers[i].hp = hp_of_soldier[buf[i]];
}
} else {
strcpy(color, "blue");
int buf[5] = {3, 0, 1, 2, 4};
for (int i = 0; i < 5; i++) {
soldiers[i].init();
strcpy(soldiers[i].name, name_of_soldier[buf[i]]);
soldiers[i].hp = hp_of_soldier[buf[i]];
}
}
}
void put_stop_make_soldier () {
printf("%03d %s headquarter stops making warriors\n",time,color);
}
void put_soldier_maked (const int x) {
printf("%03d %s %s %d born with strength %d,", time, color, soldiers[x].name, number_of_new_soldier, soldiers[x].hp);
printf("%d %s in %s headquarter\n", soldiers[x].rest, soldiers[x].name, color);
//printf("%d\n",next_soldier);
}
void make_soldier () {
bool maked = 0;
if(cant_make_soldier)return;
//printf("%d\n", next_soldier);
if (soldiers[next_soldier].hp > hp_of_headquarter) {
for (int i = 0; i < 5; i++, next_soldier++) {
if (next_soldier>=5) next_soldier = 0;
if (soldiers[next_soldier].hp <= hp_of_headquarter){
maked = 1;
break;
}
}
} else maked = 1;
if (maked) {
hp_of_headquarter -= soldiers[next_soldier].hp;
soldiers[next_soldier].number++;
soldiers[next_soldier].rest++;
number_of_new_soldier++;
put_soldier_maked(next_soldier);
next_soldier++;
if (next_soldier>=5) next_soldier = 0;
} else {
cant_make_soldier = 1;
put_stop_make_soldier();
}
}
};
T red, blue;
int main()
{
#ifdef LOCAL
freopen("moshou1.in", "r", stdin);
freopen("moshou1.out", "w", stdout);
#endif
int t;
scanf("%d",&t);
for(int l = 1; l <= t; l++){
int m;
time = 0;
for(int i = 0; i < 5; i++) scanf("%d", &hp_of_soldier[i]);
red.init(1, m);
blue.init(0, m);
printf("Case:%d\n", l);
for(;!(red.cant_make_soldier && blue.cant_make_soldier); time++){
red.make_soldier();
blue.make_soldier();
}
}
return 0;
}
後面還要改一些內容來支持後兩道題的擴展需求