雖然寫的很難看,也有錯的地方。 過了在此留個紀念,這也算爲數不多的長的程序
描述魔獸世界的西面是紅魔軍的司令部,東面是藍魔軍的司令部。兩個司令部之間是依次排列的若干城市,城市從西向東依次編號爲1,2,3 .... N ( N <= 20 )。紅魔軍的司令部算作編號爲0的城市,藍魔軍的司令部算作編號爲N+1的城市。司令部有生命元,用於製造武士。
兩軍的司令部都會製造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五種。每種武士都有編號、生命值、攻擊力這三種屬性。
雙方的武士編號都是從1開始計算。紅方製造出來的第 n 個武士,編號就是n。同樣,藍方製造出來的第 n 個武士,編號也是n。
武士在剛降生的時候有一個初始的生命值,生命值在戰鬥中會發生變化,如果生命值減少到0(生命值變爲負數時應當做變爲0處理),則武士死亡(消失)。
有的武士可以擁有武器。武器有三種,sword, bomb,和arrow,編號分別爲0,1,2。
武士降生後就朝對方司令部走,在經過的城市如果遇到敵人(同一時刻每個城市最多隻可能有1個藍武士和一個紅武士),就會發生戰鬥。每次戰鬥只有一方發起主動進攻一次。被攻擊者生命值會減去進攻者的攻擊力值和進攻者手中sword的攻擊力值。被進攻者若沒死,就會發起反擊,被反擊者的生命值要減去反擊者攻擊力值的一半(去尾取整)和反擊者手中sword的攻擊力值。反擊可能致敵人於死地。
如果武士在戰鬥中殺死敵人(不論是主動進攻殺死還是反擊殺死),則其司令部會立即向其發送8個生命元作爲獎勵,使其生命值增加8。當然前提是司令部得有8個生命元。如果司令部的生命元不足以獎勵所有的武士,則優先獎勵距離敵方司令部近的武士。
如果某武士在某城市的戰鬥中殺死了敵人,則該武士的司令部立即取得該城市中所有的生命元。注意,司令部總是先完成全部獎勵工作,然後纔開始從各個打了勝仗的城市回收生命元。對於因司令部生命元不足而領不到獎勵的武士,司令部也不會在取得戰利品生命元后爲其補發獎勵。
如果一次戰鬥的結果是雙方都倖存(平局),則雙方都不能拿走發生戰鬥的城市的生命元。
城市可以插旗子,一開始所有城市都沒有旗子。在插紅旗的城市,以及編號爲奇數的無旗城市,由紅武士主動發起進攻。在插藍旗的城市,以及編號爲偶數的無旗城市,由藍武士主動發起進攻。
當某個城市有連續兩場戰鬥都是同一方的武士殺死敵人(兩場戰鬥之間如果有若干個戰鬥時刻並沒有發生戰鬥,則這兩場戰鬥仍然算是連續的;但如果中間有平局的戰鬥,就不算連續了) ,那麼該城市就會插上勝方的旗幟,若原來插着敗方的旗幟,則敗方旗幟落下。旗幟一旦插上,就一直插着,直到被敵人更換。一個城市最多隻能插一面旗幟,旗幟沒被敵人更換前,也不會再次插同顏色的旗。
各種武器有其特點:
sword武器的初始攻擊力爲擁有它的武士的攻擊力的20%(去尾取整)。但是sword每經過一次戰鬥(不論是主動攻擊還是反擊),就會變鈍,攻擊力變爲本次戰鬥前的80% (去尾取整)。sword攻擊力變爲0時,視爲武士失去了sword。如果武士降生時得到了一個初始攻擊力爲0的sword,則視爲武士沒有sword.
arrow有一個攻擊力值R。如果下一步要走到的城市有敵人,那麼擁有arrow的武士就會放箭攻擊下一個城市的敵人(不能攻擊對方司令部裏的敵人)而不被還擊。arrow使敵人的生命值減少R,若減至小於等於0,則敵人被殺死。arrow使用3次後即被耗盡,武士失去arrow。兩個相鄰的武士可能同時放箭把對方射死。
擁有bomb的武士,在戰鬥開始前如果判斷自己將被殺死(不論主動攻擊敵人,或者被敵人主動攻擊都可能導致自己被殺死,而且假設武士可以知道敵人的攻擊力和生命值),那麼就會使用bomb和敵人同歸於盡。武士不預測對方是否會使用bomb。
武士使用bomb和敵人同歸於盡的情況下,不算是一場戰鬥,雙方都不能拿走城市的生命元,也不影響城市的旗幟。
不同的武士有不同的特點。
dragon可以擁有一件武器。編號爲n的dragon降生時即獲得編號爲 n%3 的武器。dragon還有“士氣”這個屬性,是個浮點數,其值爲它降生後其司令部剩餘生命元的數量除以造dragon所需的生命元數量。dragon 在一次在它主動進攻的戰鬥結束後,如果還沒有戰死,而且士氣值大於0.8,就會歡呼。dragon每取得一次戰鬥的勝利(敵人被殺死),士氣就會增加0.2,每經歷一次未能獲勝的戰鬥,士氣值就會減少0.2。士氣增減發生在歡呼之前。
ninjia可以擁有兩件武器。編號爲n的ninjia降生時即獲得編號爲 n%3 和 (n+1)%3的武器。ninja 捱打了也從不反擊敵人。
iceman有一件武器。編號爲n的iceman降生時即獲得編號爲 n%3 的武器。iceman 每前進兩步,在第2步完成的時候,生命值會減少9,攻擊力會增加20。但是若生命值減9後會小於等於0,則生命值不減9,而是變爲1。即iceman不會因走多了而死。
lion 有“忠誠度”這個屬性,其初始值等於它降生之後其司令部剩餘生命元的數目。每經過一場未能殺死敵人的戰鬥,忠誠度就降低K。忠誠度降至0或0以下,則該lion逃離戰場,永遠消失。但是已經到達敵人司令部的lion不會逃跑。Lion在己方司令部可能逃跑。lion 若是戰死,則其戰鬥前的生命值就會轉移到對手身上。所謂“戰鬥前”,就是每個小時的40分前的一瞬間。
wolf降生時沒有武器,但是在戰鬥中如果獲勝(殺死敵人),就會繳獲敵人的武器,但自己已有的武器就不繳獲了。被繳獲的武器當然不能算新的,已經被用到什麼樣了,就是什麼樣的。
以下是不同時間會發生的不同事件:
在每個整點,即每個小時的第0分, 雙方的司令部中各有一個武士降生。
紅方司令部按照 iceman、lion、wolf、ninja、dragon 的順序製造武士。
藍方司令部按照 lion、dragon、ninja、iceman、wolf 的順序製造武士。
製造武士需要生命元。
製造一個初始生命值爲 m 的武士,司令部中的生命元就要減少 m 個。
如果司令部中的生命元不足以製造某武士,那麼司令部就等待,直到獲得足夠生命元后的第一個整點,才製造該武士。例如,在2:00,紅方司令部本該製造一個 wolf ,如果此時生命元不足,那麼就會等待,直到生命元足夠後的下一個整點,才製造一個 wolf。
在每個小時的第5分,該逃跑的lion就在這一時刻逃跑了。
在每個小時的第10分:所有的武士朝敵人司令部方向前進一步。即從己方司令部走到相鄰城市,或從一個城市走到下一個城市。或從和敵軍司令部相鄰的城市到達敵軍司令部。
在每個小時的第20分:每個城市產出10個生命元。生命元留在城市,直到被武士取走。
在每個小時的第30分:如果某個城市中只有一個武士,那麼該武士取走該城市中的所有生命元,並立即將這些生命元傳送到其所屬的司令部。
在每個小時的第35分,擁有arrow的武士放箭,對敵人造成傷害。放箭事件應算髮生在箭發出的城市。注意,放箭不算是戰鬥,因此放箭的武士不會得到任何好處。武士在沒有敵人的城市被箭射死也不影響其所在城市的旗幟更換情況。
在每個小時的第38分,擁有bomb的武士評估是否應該使用bomb。如果是,就用bomb和敵人同歸於盡。
在每個小時的第40分:在有兩個武士的城市,會發生戰鬥。 如果敵人在5分鐘前已經被飛來的arrow射死,那麼仍然視爲發生了一場戰鬥,而且存活者視爲獲得了戰鬥的勝利。此情況下不會有“武士主動攻擊”,“武士反擊”,“武士戰死”的事件發生,但戰鬥勝利後應該發生的事情都會發生。如Wolf一樣能繳獲武器,旗幟也可能更換,等等。在此情況下,Dragon同樣會通過判斷是否應該輪到自己主動攻擊來決定是否歡呼。
在每個小時的第50分,司令部報告它擁有的生命元數量。
在每個小時的第55分,每個武士報告其擁有的武器情況。
武士到達對方司令部後就算完成任務了,從此就呆在那裏無所事事。
任何一方的司令部裏若是出現了2個敵人,則認爲該司令部已被敵人佔領。
任何一方的司令部被敵人佔領,則戰爭結束。戰爭結束之後就不會發生任何事情了。
給定一個時間,要求你將從0點0分開始到此時間爲止的所有事件按順序輸出。事件及其對應的輸出樣例如下:
- 1) 武士降生
-
輸出樣例: 000:00 blue lion 1 born
表示在 0點0分,編號爲1的藍魔lion武士降生
如果造出的是dragon,那麼還要多輸出一行,例:000:00 blue dragon 1 born
Its morale is 23.34
表示該該dragon降生時士氣是23. 34(四捨五入到小數點後兩位)如果造出的是lion,那麼還要多輸出一行,例:
000:00 blue lion 1 born
Its loyalty is 24
表示該lion降生時的忠誠度是24 - 2) lion逃跑
-
輸出樣例: 000:05 blue lion 1 ran away
表示在 0點5分,編號爲1的藍魔lion武士逃走 - 3) 武士前進到某一城市
-
輸出樣例: 000:10 red iceman 1 marched to city 1 with 20 elements and force 30
表示在 0點10分,紅魔1號武士iceman前進到1號城市,此時他生命值爲20,攻擊力爲30
對於iceman,輸出的生命值和攻擊力應該是變化後的數值 - 4)武士放箭
-
輸出樣例: 000:35 blue dragon 1 shot
表示在 0點35分,編號爲1的藍魔dragon武士射出一支箭。如果射出的箭殺死了敵人,則應如下輸出:
000:35 blue dragon 1 shot and killed red lion 4
表示在 0點35分,編號爲1的藍魔dragon武士射出一支箭,殺死了編號爲4的紅魔lion。 - 5)武士使用bomb
-
輸出樣例: 000:38 blue dragon 1 used a bomb and killed red lion 7
表示在 0點38分,編號爲1的藍魔dragon武士用炸彈和編號爲7的紅魔lion同歸於盡。 - 6) 武士主動進攻
-
輸出樣例: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 - 7) 武士反擊
-
輸出樣例:001:40 blue dragon 2 fought back against red lion 2 in city 1
表示在1點40分,1號城市中,藍魔2號武士dragon反擊紅魔2號武士lion - 8) 武士戰死
-
輸出樣例:001:40 red lion 2 was killed in city 1
被箭射死的武士就不會有這一條輸出。 - 9) 武士歡呼
-
輸出樣例:003:40 blue dragon 2 yelled in city 4
- 10) 武士獲取生命元( elements )
-
輸出樣例:001:40 blue dragon 2 earned 10 elements for his headquarter
- 11) 旗幟升起
-
輸出樣例:004:40 blue flag raised in city 4
- 12) 武士抵達敵軍司令部
-
輸出樣例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
(此時他生命值爲20,攻擊力爲30)對於iceman,輸出的生命值和攻擊力應該是變化後的數值 - 13) 司令部被佔領
-
輸出樣例:003:10 blue headquarter was taken
- 14)司令部報告生命元數量
-
000:50 100 elements in red headquarter
000:50 120 elements in blue headquarter
表示在0點50分,紅方司令部有100個生命元,藍方有120個 - 15)武士報告武器情況
-
000:55 blue wolf 2 has arrow(2),bomb,sword(23)
000:55 blue wolf 4 has no weapon
000:55 blue wolf 5 has sword(20)
表示在0點55分,藍魔2號武士wolf有一支arrow(這支arrow還可以用2次),一個bomb,還有一支攻擊力爲23的sword。
藍魔4號武士wolf沒武器。
藍魔5號武士wolf有一支攻擊力爲20的sword。
交代武器情況時,次序依次是:arrow,bomb,sword。如果沒有某種武器,某種武器就不用提。報告時,先按從西向東的順序所有的紅武士報告,然後再從西向東所有的藍武士報告。
輸出事件時:
首先按時間順序輸出;
同一時間發生的事件,按發生地點從西向東依次輸出. 武士前進的事件, 算是發生在目的地。
在一次戰鬥中有可能發生上面的 6 至 11 號事件。這些事件都算同時發生,其時間就是戰鬥開始時間。一次戰鬥中的這些事件,序號小的應該先輸出。
兩個武士同時抵達同一城市,則先輸出紅武士的前進事件,後輸出藍武士的。
顯然,13號事件發生之前的一瞬間一定發生了12號事件。輸出時,這兩件事算同一時間發生,但是應先輸出12號事件
雖然任何一方的司令部被佔領之後,就不會有任何事情發生了。但和司令部被佔領同時發生的事件,全都要輸出。
輸入
第一行是t,代表測試數據組數
每組樣例共三行。
第一行,五個整數 M,N,R,K, T。其含義爲:
每個司令部一開始都有M個生命元( 1 <= M <= 1000)
兩個司令部之間一共有N個城市( 1 <= N <= 20 )
arrow的攻擊力是R
lion每經過一場未能殺死敵人的戰鬥,忠誠度就降低K。
要求輸出從0時0分開始,到時間T爲止(包括T) 的所有事件。T以分鐘爲單位,0 <= T <= 5000
第二行:五個整數,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它們都大於0小於等於100
第三行:五個整數,依次是 dragon 、ninja、iceman、lion、wolf 的攻擊力。它們都大於0小於等於100
對每組數據,先輸出一行:
Case n:
如對第一組數據就輸出 Case1:
然後按恰當的順序和格式輸出到時間T爲止發生的所有事件。每個事件都以事件發生的時間開頭,時間格式是“時: 分”,“時”有三位,“分”有兩位。
1 20 1 10 10 1000 20 20 30 10 20 5 5 5 5 5樣例輸出
Case 1: 000:00 blue lion 1 born Its loyalty is 10 000:10 blue lion 1 marched to city 1 with 10 elements and force 5 000:30 blue lion 1 earned 10 elements for his headquarter 000:50 20 elements in red headquarter 000:50 20 elements in blue headquarter 000:55 blue lion 1 has no weapon 001:00 blue dragon 2 born Its morale is 0.00 001:10 blue lion 1 reached red headquarter with 10 elements and force 5 001:10 blue dragon 2 marched to city 1 with 20 elements and force 5 001:30 blue dragon 2 earned 10 elements for his headquarter 001:50 20 elements in red headquarter 001:50 10 elements in blue headquarter 001:55 blue lion 1 has no weapon 001:55 blue dragon 2 has arrow(3) 002:10 blue dragon 2 reached red headquarter with 20 elements and force 5 002:10 red headquarter was taken
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
const int NUM = 10;
const int nameLen = 10;
const int cityNumber = 200;
const int MAXN_N = 100000;
// 0 red 1 blue
using namespace std;
int MonsterHP[NUM], MonsterAttack[NUM];
int M,N,R,K,T;
int redArrival,blueArrival;
bool finish;
class Clock
{
private:
int hour, minute;
public:
Clock(int _hour = 0, int _minute = 0):hour(_hour),minute(_minute){}
~Clock(){}
void init()
{
hour = minute = 0;
}
void next()
{
minute++;
if (minute == 60)
{
hour ++; minute = 0;
}
}
void print()
{
printf("%03d:%02d", hour,minute);
}
int getMinute()
{
return minute;
}
int getHour()
{
return hour;
}
};//Time Class record time
Clock myClock(0,0);
class Monster;
class City
{
public:
int HP;
Monster * monster[2];
int flagColor;
int lastWin;
int transformHP()
{
int _HP = HP;
HP = 0;
return _HP;
}
void changeFlag()
{
}
friend class Monster;
}city[cityNumber];
class HEADQUARTER
{
public:
int TotalHP;
int number;
int Add;
HEADQUARTER()
{
Add = 0;
TotalHP =0;
number =0;
}
Monster * QueueMonster[MAXN_N];
void printInfo(const char * color)
{
myClock.print();
printf(" %d elements in %s headquarter\n",TotalHP,color);
}
friend class Monster;
}head[2];
class Weapon
{
public:
int AttackValue;
Weapon(int _AttackValue = 0):AttackValue(_AttackValue)
{
}
virtual void Info(){};
friend class Monster;
};
class Sword:public Weapon
{
public:
Sword(int _AttackValue):Weapon(_AttackValue)
{
}
void Info()
{
printf("sword(%d)",AttackValue);
}
};
class Bomb:public Weapon
{
public:
Bomb():Weapon(0)
{
}
virtual void Info()
{
printf("bomb");
}
};
class Arrow:public Weapon
{
public:
int Times;
Arrow()
{
Times = 3;
AttackValue = R;
}
int use()
{
Times--;
return Times;
}
int getTimes()
{
return Times;
}
virtual void Info()
{
printf("arrow(%d)",Times);
}
};
class Monster
{
public:
char * name;
int Id;
int HP, Attack;
int color;
Weapon * weapon[3];
int step;
Monster(int _Id, int _HP, int _Attack,int _color, char * _name):Id(_Id),HP(_HP),Attack(_Attack),color(_color)
{
name = new char[strlen(_name)+1];
strcpy(name,_name);
if (color == 0)
head[0].number ++; else head[1].number ++;
head[color].TotalHP -=HP;
for (int i = 0; i < 3;++i) weapon[i] = NULL;
step = 0;
myClock.print();
printf(" %s %s %d %s\n",(color?"blue":"red"),name,Id,"born");
}
~Monster(){}
bool isDragon()
{
if (name[0]=='d') return true; else return false;
}
bool isNija()
{
if (name[0]=='n') return true; else return false;
}
bool isIceman()
{
if (name[0]=='i') return true; else return false;
}
bool isLion()
{
if (name[0]=='l') return true;else return false;
}
bool isWolf()
{
if (name[0]=='w') return true; else return false;
}
void printForward(int cityNumber)
{
step++;
myClock.print();
printf(" %s %s %d marched to city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,cityNumber,HP,Attack);
}
void arrowAttack(Monster * p)
{
if (this->weapon[0] ==NULL) return ;
p->HP-=this->weapon[0]->AttackValue;
((Arrow *)this->weapon[0])->use();
if (((Arrow *)this->weapon[0])->getTimes()==0)
{
delete (Arrow *)this->weapon[0];
this->weapon[0] = NULL;
}
myClock.print();
if (p->HP>0) printf(" %s %s %d shot\n",(color==0?"red":"blue"),name,Id); else
printf(" %s %s %d shot and killed %s %s %d\n",(color==0?"red":"blue"),name,Id,
(p->color==0?"red":"blue"),p->name,p->Id);
}
void getWeaponInfo()
{
myClock.print();
bool has = false;
//cout<<"AAJAJJA"<< (weapon[1]==NULL)<<endl;
for (int j = 0; j < 3;++j)
{
int i = j;
if (j==1) i=2;
if (j==2) i=1;
if (i==1)
{
if(weapon[i] != NULL)
if (weapon[i]->AttackValue==0) weapon[i]=NULL;
}
if(weapon[i] != NULL)
{
if (!has)
{
has = true;
printf(" %s %s %d has ",(color==0?"red":"blue"),name,Id);
} else printf(",");
weapon[i]->Info();
}
}
if (!has) printf(" %s %s %d has no weapon",(color==0?"red":"blue"),name,Id);
printf("\n");
}
bool canKilled(int cityId, Monster * p )
{
if (city[cityId].flagColor == color || (city[cityId].flagColor == -1 &&cityId%2==1-color))
{
if (p->isNija()) return false;
if (p->HP <= Attack+(weapon[1]!=NULL? weapon[1]->AttackValue:0))
return false;
else if (HP>p->Attack/2+(p->weapon[1]!=NULL?p->weapon[1]->AttackValue:0))
return false;
else
return true;
} else
{
if (HP>p->Attack+(p->weapon[1]!=NULL?p->weapon[1]->AttackValue:0))
return false;
else
return true;
}
}
int getCityHPforhisHead(int cityHP)
{
myClock.print();
printf(" %s %s %d earned %d elements for his headquarter\n",(color==0?"red":"blue"),
name,Id,cityHP);
head[color].Add+=cityHP;
return cityHP;
}
friend class HEADQUATER;
friend class city;
friend class Weapon;
//virtual void AttackOther(Monster *);
//virtual void Hurt(Monster &);
//virtual void FightBack(Monster *);
virtual void AttackOther(Monster *p,int cityId)
{
}
virtual void FightBack(Monster *p,int cityId)
{
}
} ;
class Dragon:public Monster
{
public:
double morale; // 士氣
Dragon(int _Id, int _HP, int _Attack,int _color, double _morale):Monster(_Id,_HP,_Attack,_color,"dragon")
,morale(_morale)
{
switch((Id+1)%3)
{
case 0:
weapon[0] = new Arrow();
break;
case 1:
weapon[1] = new Sword(int(Attack*0.2));
break;
case 2:
weapon[2] = new Bomb();
break;
default:
break;
}
printf("Its morale is %.2lf\n",morale);
}
~Dragon(){};
void happy(int cityId)
{
if (morale>=0.8)
{
myClock.print();
printf(" %s dragon %d yelled in city %d\n",
(color==0?"red":"blue"),Id,cityId);
}
}
void changeMorale(double delta)
{
morale+=delta;
}
virtual void AttackOther(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
//this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId,HP,Attack);
p->HP -= Attack;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
morale +=0.2; else morale -=0.2;
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
//this->happy(cityId);
//this->getCityHPforhisHead(city[cityId].transformHP());
}
}
virtual void FightBack(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
//this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d fought back against %s %s %d in city %d\n"
,(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId);
p->HP -= Attack/2;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0) morale +=0.2; else morale -=0.2;
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
//this->getCityHPforhisHead(city[cityId].transformHP());
}
}
};
class Ninja:public Monster
{
public:
Ninja(int _Id, int _HP, int _Attack,int _color):Monster(_Id,_HP,_Attack,_color,"ninja")
{
for (int _id = Id; _id<=Id+1; ++_id)
switch((_id+1)%3)
{
case 0:
weapon[0] = new Arrow();
break;
case 1:
weapon[1] = new Sword(int(Attack*0.2));
break;
case 2:
weapon[2] = new Bomb();
break;
}
}
~Ninja(){}
virtual void AttackOther(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId,HP,Attack);
p->HP -= Attack;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
virtual void FightBack(Monster * p,int cityId)
{
}
};
class Iceman:public Monster
{
public:
Iceman(int _Id, int _HP, int _Attack,int _color):Monster(_Id,_HP,_Attack,_color,"iceman")
{
step=0;
switch((Id+1)%3)
{
case 0:
weapon[0] = new Arrow();
break;
case 1:
weapon[1] = new Sword(int(Attack*0.2));
break;
case 2:
weapon[2] = new Bomb();
break;
}
}
~Iceman(){};
virtual void AttackOther(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId,HP,Attack);
p->HP -= Attack;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
virtual void FightBack(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d fought back against %s %s %d in city %d\n"
,(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId);
p->HP -= Attack/2;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
void change()
{
if (step>0 && step%2==1)
{
if (HP>9) { HP-=9, Attack+=20;} else
{ HP =1, Attack+=20;}
}
}
};
class Lion:public Monster
{
public:
int loyalty; // 忠誠度
Lion(int _Id, int _HP, int _Attack,int _color,int _loyalty):Monster(_Id,_HP,_Attack,_color,"lion"),loyalty(_loyalty)
{
printf("Its loyalty is %d\n",loyalty);
}
~Lion(){};
void downLoy()
{
loyalty-=K;
}
virtual void AttackOther(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId,HP,Attack);
p->HP -= Attack;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
virtual void FightBack(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d fought back against %s %s %d in city %d\n"
,(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId);
p->HP -= Attack/2;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
bool escape()
{
if (loyalty<=0)
{
// HP = 0;
myClock.print();
printf(" %s %s %d ran away\n",(color==0?"red":"blue"),name,Id);
return true;
} else
return false;
}
};
class Wolf:public Monster
{
public:
Wolf(int _Id, int _HP, int _Attack,int _color):Monster(_Id,_HP,_Attack,_color,"wolf")
{
}
~Wolf(){}
void tune()
{
if (weapon[0] != NULL)
{
if (((Arrow *)weapon[0])->getTimes()==0)
{
delete weapon[0];
weapon[0]= NULL;
}
}
if (weapon[1] != NULL)
{
if (((Sword *)weapon[1])->AttackValue==0)
{
delete weapon[1];
weapon[1]= NULL;
}
}
}
void getWeapon(Monster * p)
{
this->tune();
for (int i = 0; i < 3;++i)
if (weapon[i]==NULL)
{
weapon[i] = p->weapon[i];
p->weapon[i] = NULL;
}
}
virtual void AttackOther(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d attacked %s %s %d in city %d with %d elements and force %d\n",
(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId,HP,Attack);
p->HP -= Attack;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0) this->getWeapon(p);
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
virtual void FightBack(Monster * p,int cityId)
{
if (HP<=0 ) return ;
if (p->HP<=0)
{
this->getCityHPforhisHead(city[cityId].transformHP());
return ;
}
int newHP = 0;
if (p->isLion()) newHP = p->HP;
myClock.print();
printf(" %s %s %d fought back against %s %s %d in city %d\n"
,(color==0?"red":"blue"),name,Id,(p->color==0?"red":"blue"),p->name,p->Id,cityId);
p->HP -= Attack/2;
if (weapon[1] != NULL) {
p->HP-= weapon[1]->AttackValue;
weapon[1]->AttackValue=int(weapon[1]->AttackValue*0.8);
}
if (p->HP<=0) this->getWeapon(p);
if (p->HP<=0)
{
myClock.print();
printf(" %s %s %d was killed in city %d\n",
(p->color==0?"red":"blue"),p->name,p->Id,cityId);
HP+=newHP;
this->getCityHPforhisHead(city[cityId].transformHP());
}
}
};
void cityCreateHP()
{
for (int i = 0; i <= N+1;++i) city[i].HP+=10;
}
void CityInit(int n)
{
for (int i = 0; i <= N+1; ++i)
{
city[i].monster[0] = NULL;
city[i].monster[1] = NULL;
city[i].flagColor = -1;
city[i].lastWin = -1;
city[i].HP =0;
}
}
void BombAttack()
{
for (int i = 1; i <= N; ++i)
{
bool AllKilled = false;
if (city[i].monster[0] != NULL && city[i].monster[1] != NULL)
if (city[i].monster[0]->HP>0 && city[i].monster[1]->HP>0)
{
if (city[i].monster[0]->canKilled(i,city[i].monster[1]) && city[i].monster[0]->weapon[2] != NULL)
{
myClock.print();
printf(" red %s %d used a bomb and killed blue %s %d\n"
,city[i].monster[0]->name,city[i].monster[0]->Id,city[i].monster[1]->name,city[i].monster[1]->Id);
AllKilled= true;
}
if (city[i].monster[1]->canKilled(i,city[i].monster[0]) && city[i].monster[1]->weapon[2] != NULL)
{
myClock.print();
printf(" blue %s %d used a bomb and killed red %s %d\n"
,city[i].monster[1]->name,city[i].monster[1]->Id,city[i].monster[0]->name,city[i].monster[0]->Id);
AllKilled= true;
}
}
if (AllKilled) city[i].monster[0] = city[i].monster[1] = NULL;
}
}
void FightOther()
{
for (int i = 1; i <= N; ++i)
{
if (city[i].monster[0] != NULL && city[i].monster[1] != NULL)
{
if (city[i].flagColor == 0 || (city[i].flagColor ==-1 && i%2==1))
{
city[i].monster[0]->AttackOther(city[i].monster[1],i);
city[i].monster[1]->FightBack(city[i].monster[0],i);
if (city[i].monster[0]->isDragon() && city[i].monster[0]->HP>0)
((Dragon *)city[i].monster[0])->happy(i);
} else
{
city[i].monster[1]->AttackOther(city[i].monster[0],i);
//if(myClock.getHour()==16 && i==8) exit(0);
city[i].monster[0]->FightBack(city[i].monster[1],i);
if (city[i].monster[1]->isDragon() && city[i].monster[1]->HP>0)
((Dragon *)city[i].monster[1])->happy(i);
}
for (int j = 0; j <2; ++j)
if (city[i].monster[j]->HP>0 && city[i].monster[1-j]->HP<=0)
if (city[i].HP>0)
city[i].monster[j]->getCityHPforhisHead(city[i].transformHP());
} else
if (city[i].monster[0] != NULL)
{
if (city[i].monster[0]->HP>0)
if (city[i].HP>0)
city[i].monster[0]->getCityHPforhisHead(city[i].transformHP());
}
else
if (city[i].monster[1] != NULL)
{
if (city[i].monster[1]->HP>0)
if (city[i].HP>0)
city[i].monster[1]->getCityHPforhisHead(city[i].transformHP());
}
int win = -1;
if (city[i].monster[0] != NULL && city[i].monster[1] !=NULL)
if (city[i].monster[0]->HP>0 || city[i].monster[1]->HP>0)
{
if (city[i].monster[0]->HP>0 && city[i].monster[1]->HP<=0) win = 0; else
if (city[i].monster[1]->HP>0 && city[i].monster[0]->HP<=0) win = 1; else
win = 2;
if (win != 2)
if (city[i].lastWin == win && win !=-1 && city[i].flagColor != win){
myClock.print();
printf(" %s flag raised in city %d\n"
,(win==0?"red":"blue"),i);
}
if (win != 2)
{
if (city[i].lastWin == -1) city[i].lastWin = win; else
{
if (city[i].lastWin == win) city[i].flagColor = win;
city[i].lastWin = win;
}
}
else city[i].lastWin = -1;
}
}
for (int i =1; i <= N;++i)
for (int j = 0; j <= 1; ++j)
{
if (city[i].monster[j] != NULL)
if (city[i].monster[j]->HP>0)
if (city[i].monster[j]->isDragon())
{
if (city[i].monster[1-j] != NULL)
{
if (city[i].monster[1-j]->HP<=0)
((Dragon *)city[i].monster[j])->changeMorale(0.2); else
((Dragon *)city[i].monster[j])->changeMorale(-0.2);
}
}
if (city[i].monster[j] != NULL)
if (city[i].monster[j]->HP>0)
if (city[i].monster[j]->isLion())
{
if (city[i].monster[1-j] != NULL)
{
if (city[i].monster[1-j]->HP>0)
((Lion *)city[i].monster[j])->downLoy();
}
}
if (city[i].monster[j] != NULL && city[i].monster[1-j] != NULL)
if (city[i].monster[j]->isWolf())
{
if (city[i].monster[j]->HP>0 && city[i].monster[1-j]->HP<=0)
{
((Wolf *)city[i].monster[j])->getWeapon(city[i].monster[1-j]);
}
}
}
for (int i = 1; i <= N;++i)
if (city[i].monster[0] != NULL && city[i].monster[1]!=NULL && city[i].lastWin ==0 && head[0].TotalHP>=8)
if (city[i].monster[0]->HP>0 && city[i].monster[1]->HP<=0)
{
city[i].monster[0]->HP+=8;
head[0].TotalHP -=8;
}
for (int i = N; i >=1;--i)
if (city[i].monster[1] != NULL && city[i].monster[0]!=NULL && city[i].lastWin ==1 && head[1].TotalHP>=8)
if (city[i].monster[1]->HP>0 && city[i].monster[0]->HP<=0)
{
city[i].monster[1]->HP+=8;
head[1].TotalHP -=8;
}
for (int i = 0; i < 2;++i)
{
head[i].TotalHP+=head[i].Add;
head[i].Add = 0;
}
for (int i = 0; i <= N+1;++i)
for (int j = 0; j <= 1; ++j)
{
if (city[i].monster[j]!= NULL)
if (city[i].monster[j]->HP<=0)
city[i].monster[j] = NULL;
}
}
void MonsterWeaponInfo()
{
for (int i = 0; i <=N+1; ++i)
if (city[i].monster[0]!=NULL)
{
city[i].monster[0]->getWeaponInfo();
}
for (int i = 0; i <= N+1; ++i)
if (city[i].monster[1]!=NULL)
{
city[i].monster[1]->getWeaponInfo();
}
}
void ArrowAttack()
{
for (int i = 0 ; i<=N+1; ++i)
{
if (i+1<=N+1)
if (city[i].monster[0] != NULL && city[i+1].monster[1] != NULL)
{
//int lastHP = city[i+1].monster[1]->HP;
city[i].monster[0]->arrowAttack(city[i+1].monster[1]);
//if (city[i+1].monster[1]->HP<=0 && city[i+1].monster[1]->isLion())
//if (city[i+1].monster[0]!= NULL)
//city[i+1].monster[0]->HP+=lastHP;
/*if (city[i+1].monster[1]->HP<0)
city[i+1].monster[1] = NULL;*/
}
if (city[i].monster[1] != NULL && city[i-1].monster[0] != NULL)
{
///int lastHP = city[i-1].monster[0]->HP;
if (i-1>=0)
city[i].monster[1]->arrowAttack(city[i-1].monster[0]);
//if (city[i-1].monster[0]->HP<=0 && city[i-1].monster[0]->isLion())
//if (city[i-1].monster[1]!=NULL)
//city[i-1].monster[1]->HP+=lastHP;
}
}
/*
for (int i = 1 ; i<=N+1; ++i)
{
if (city[i].monster[1] != NULL && city[i-1].monster[0] != NULL)
{
///int lastHP = city[i-1].monster[0]->HP;
city[i].monster[1]->arrowAttack(city[i-1].monster[0]);
//if (city[i-1].monster[0]->HP<=0 && city[i-1].monster[0]->isLion())
//if (city[i-1].monster[1]!=NULL)
//city[i-1].monster[1]->HP+=lastHP;
}
}
*/
}
void getCityHP()
{
for (int i = 1; i <= N;++i)
{
for (int j = 0; j <= 1;++j)
if (city[i].monster[j] !=NULL && city[i].monster[1-j] == NULL && city[i].HP>0)
{
city[i].monster[j]->getCityHPforhisHead(city[i].transformHP());
//head[j].TotalHP+= city[i].transformHP();
}
}
for (int i = 0; i < 2;++i)
{
head[i].TotalHP+=head[i].Add;
head[i].Add =0;
}
}
void forward()
{
/*
if (city[N].monster[0]!=NULL && city[N+1].monster[0] != NULL){
finish = true;
myClock.print();
printf(" blue headquarter was taken\n");
return ;
}
if (city[0].monster[1]!=NULL && city[1].monster[1] != NULL){
finish = true;
myClock.print();
printf(" red headquarter was taken\n");
return ;
}
*/
City A = city[1];
City B = city[N];
for (int i = N; i >=0; --i)
{
if ((i==N && city[i].monster[0]!=NULL) || i!=N)
city[i+1].monster[0] = city[i].monster[0];
city[i].monster[0] = NULL;
}
for (int i = 0; i<= N; ++i)
{
if ((i==0 && city[i+1].monster[1]!=NULL) || i!=0)
city[i].monster[1] = city[i+1].monster[1];
city[i+1].monster[1] = NULL;
}
if (A.monster[1] != NULL)
{
if (A.monster[1]->isIceman())
((Iceman *)A.monster[1])->change();
myClock.print();
printf(" blue %s %d reached red headquarter with %d elements and force %d\n"
,A.monster[1]->name,A.monster[1]->Id,A.monster[1]->HP,
A.monster[1]->Attack);
blueArrival++;
if (blueArrival==2)
{
finish = true;
myClock.print();
printf(" red headquarter was taken\n");
}
}
for (int i = 1; i <= N;++i)
{
if (city[i].monster[0] != NULL)
{
if (city[i].monster[0]->isIceman())
((Iceman *)city[i].monster[0])->change();
//myClock.print();
city[i].monster[0]->printForward(i);
}
if (city[i].monster[1] != NULL)
{
if (city[i].monster[1]->isIceman())
((Iceman *) city[i].monster[1])->change();
//myClock.print();
city[i].monster[1]->printForward(i);
}
}
if (B.monster[0] != NULL)
{
if (B.monster[0]->isIceman())
((Iceman *)B.monster[0])->change();
myClock.print();
printf(" red %s %d reached blue headquarter with %d elements and force %d\n"
,B.monster[0]->name,B.monster[0]->Id,B.monster[0]->HP,
B.monster[0]->Attack);
redArrival ++;
if (redArrival==2)
{
finish = true;
myClock.print();
printf(" blue headquarter was taken\n");
}
}
};
void lionAway()
{
for (int i = 0; i <= N+1;++i)
{
if (city[i].monster[0] != NULL)
if (city[i].monster[0]->isLion() && i!=N+1)
{
if (((Lion *)city[i].monster[0])->escape())
city[i].monster[0] = NULL;
}
if (city[i].monster[1] != NULL)
if (city[i].monster[1]->isLion() && i!=0)
{
if (((Lion *)city[i].monster[1])->escape() && i!=0)
city[i].monster[1] = NULL;
}
}
}
void product()
{
int i = head[0].number;
//iceman、lion、wolf、ninja、dragon
switch(i%5)
{
case 0:
if (MonsterHP[3]<=head[0].TotalHP)
head[0].QueueMonster[i] = new Iceman(i+1, MonsterHP[3],MonsterAttack[3],0);
break;
case 1:
if (MonsterHP[4]<=head[0].TotalHP)
head[0].QueueMonster[i] = new Lion(i+1, MonsterHP[4],MonsterAttack[4],0,
(head[0].TotalHP-MonsterHP[4]));
break;
case 2:
if (MonsterHP[5]<=head[0].TotalHP)
head[0].QueueMonster[i] = new Wolf(i+1, MonsterHP[5],MonsterAttack[5],0);
break;
case 3:
if (MonsterHP[2]<=head[0].TotalHP)
head[0].QueueMonster[i] = new Ninja(i+1, MonsterHP[2],MonsterAttack[2],0);
break;
case 4:
if (MonsterHP[1]<=head[0].TotalHP)
head[0].QueueMonster[i] = new Dragon(i+1, MonsterHP[1],MonsterAttack[1],0,
(head[0].TotalHP*1.0/MonsterHP[1]-1));
break;
}
if (head[0].number>i) city[0].monster[0] = head[0].QueueMonster[i];
i = head[1].number;
//lion、dragon、ninja、iceman、wolf
switch(i%5)
{
case 0:
if (MonsterHP[4]<=head[1].TotalHP)
head[1].QueueMonster[i] = new Lion(i+1, MonsterHP[4],MonsterAttack[4],1,
head[1].TotalHP-MonsterHP[4]);
break;
case 1:
if (MonsterHP[1]<=head[1].TotalHP)
head[1].QueueMonster[i] = new Dragon(i+1, MonsterHP[1],MonsterAttack[1],1,
(head[1].TotalHP*1.0/MonsterHP[1]-1));
break;
case 2:
if (MonsterHP[2]<=head[1].TotalHP)
head[1].QueueMonster[i] = new Ninja(i+1, MonsterHP[2],MonsterAttack[2],1);
break;
case 3:
if (MonsterHP[3]<=head[1].TotalHP)
head[1].QueueMonster[i] = new Iceman(i+1, MonsterHP[3],MonsterAttack[3],1);
break;
case 4:
if (MonsterHP[5]<=head[1].TotalHP)
head[1].QueueMonster[i] = new Wolf(i+1, MonsterHP[5],MonsterAttack[5],1);
break;
}
if (head[1].number>i) city[N+1].monster[1] = head[1].QueueMonster[i];
}
void clear()
{
for (int j = 0; j <=1;++j)
for (int i = 0; i <= head[j].number;++i)
if (head[j].QueueMonster[i]!=NULL)
{
delete head[j].QueueMonster[i];
head[j].QueueMonster[i] =NULL;
}
}
void work()
{
redArrival =blueArrival =0;
myClock.init();
cin>>M>>N>>R>>K>>T;
CityInit(N);
head[0].TotalHP = head[1].TotalHP = M;
head[0].number = head[1].number = 0;
//dragon 、ninja、iceman、lion、wolf
for (int i = 1; i <= 5; ++i) cin>>MonsterHP[i];
for (int i = 1; i <= 5; ++i) cin>>MonsterAttack[i];
finish = false;
for (int t = 0; t <= T; ++t)
{
switch(myClock.getMinute())
{
case 0:
product();
break;
case 5://lion away
lionAway();
break;
case 10:
forward();
if (finish) {clear();return ;}
break;
case 20:
cityCreateHP();
break;
case 30:
getCityHP();
break;
case 35:
ArrowAttack();
break;
case 38:
BombAttack();
break;
case 40:
FightOther();
break;
case 50:
head[0].printInfo("red");
head[1].printInfo("blue");
break;
case 55:
MonsterWeaponInfo();
break;
}
myClock.next();
}
clear();
}
int main()
{
//freopen("11.in","r",stdin);
//freopen("1.out","w",stdout);
int Test;
cin>>Test;
for (int test = 1; test<= Test; ++test)
{
printf("Case %d:\n",test);
work();
}
return 0;
}