魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市,城市从西向东依次编号为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。
sword的攻击力是使用者当前攻击力的20%(去尾取整)。
bomb的攻击力是使用者当前攻击力的40%(去尾取整),但是也会导致使用者受到攻击,对使用者的攻击力是对敌人取整后的攻击力的1/2(去尾取整)。Bomb一旦使用就没了。
arrow的攻击力是使用者当前攻击力的30%(去尾取整)。一个arrow用两次就没了。
武士降生后就朝对方司令部走,在经过的城市如果遇到敌人(同一时刻每个城市最多只可能有1个蓝武士和一个红武士),就会发生战斗。战斗的规则是:
在奇数编号城市,红武士先发起攻击
在偶数编号城市,蓝武士先发起攻击
战斗开始前,双方先对自己的武器排好使用顺序,然后再一件一件地按顺序使用。编号小的武器,排在前面。若有多支arrow,用过的排在前面。排好序后,攻击者按此排序依次对敌人一件一件地使用武器。如果一种武器有多件,那就都要用上。每使用一件武器,被攻击者生命值要减去武器攻击力。如果任何一方生命值减为0或小于0即为死去。有一方死去,则战斗结束。
双方轮流使用武器,甲用过一件,就轮到乙用。某一方把自己所有的武器都用过一轮后,就从头开始再用一轮。如果某一方没有武器了,那就挨打直到死去或敌人武器用完。武器排序只在战斗前进行,战斗中不会重新排序。
如果双方武器都用完且都还活着,则战斗以平局结束。如果双方都死了,也算平局。
有可能由于武士自身攻击力太低,而导致武器攻击力为0。攻击力为0的武器也要使用。如果战斗中双方的生命值和武器的状态都不再发生变化,则战斗结束,算平局。
战斗的胜方获得对方手里的武器。武士手里武器总数不超过10件。缴获武器时,按照武器种类编号从小到大缴获。如果有多件arrow,优先缴获没用过的。
如果战斗开始前双方都没有武器,则战斗视为平局。如果先攻击方没有武器,则由后攻击方攻击。
不同的武士有不同的特点。
编号为n的dragon降生时即获得编号为n%3 的武器。dragon在战斗结束后,如果还没有战死,就会欢呼。
编号为n的ninjia降生时即获得编号为n%3 和(n+1)%3的武器。ninja 使用bomb不会让自己受伤。
编号为n的iceman降生时即获得编号为n%3 的武器。iceman每前进一步,生命值减少10%(减少的量要去尾取整)。
编号为n的lion降生时即获得编号为n%3 的武器。lion 有“忠诚度”这个属性,其初始值等于它降生之后其司令部剩余生命元的数目。每前进一步忠诚度就降低K。忠诚度降至0或0以下,则该lion逃离战场,永远消失。但是已经到达敌人司令部的lion不会逃跑。lion在己方司令部可能逃跑。
wolf降生时没有武器,但是在战斗开始前会抢到敌人编号最小的那种武器。如果敌人有多件这样的武器,则全部抢来。Wolf手里武器也不能超过10件。如果敌人arrow太多没法都抢来,那就先抢没用过的。如果敌人也是wolf,则不抢武器。
以下是不同时间会发生的不同事件:
在每个整点,即每个小时的第0分, 双方的司令部中各有一个武士降生。
红方司令部按照iceman、lion、wolf、ninja、dragon 的顺序制造武士。
蓝方司令部按照lion、dragon、ninja、iceman、wolf 的顺序制造武士。
制造武士需要生命元。
制造一个初始生命值为m 的武士,司令部中的生命元就要减少m 个。
如果司令部中的生命元不足以制造某本该造的武士,那就从此停止制造武士。
在每个小时的第5分,该逃跑的lion就在这一时刻逃跑了。
在每个小时的第10分:所有的武士朝敌人司令部方向前进一步。即从己方司令部走到相邻城市,或从一个城市走到下一个城市。或从和敌军司令部相邻的城市到达敌军司令部。
在每个小时的第35分:在有wolf及其敌人的城市,wolf要抢夺对方的武器。
在每个小时的第40分:在有两个武士的城市,会发生战斗。
在每个小时的第50分,司令部报告它拥有的生命元数量。
在每个小时的第55分,每个武士报告其拥有的武器情况。
武士到达对方司令部后就算完成任务了,从此就呆在那里无所事事。
任何一方的司令部里若是出现了敌人,则认为该司令部已被敌人占领。
任何一方的司令部被敌人占领,则战争结束。战争结束之后就不会发生任何事情了。
给定一个时间,要求你将从0点0分开始到此时间为止的所有事件按顺序输出。事件及其对应的输出样例如下:
1) 武士降生
输出样例:000:00 blue dragon 1 born
表示在0点0分,编号为1的蓝魔dragon武士降生
如果造出的是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) wolf抢敌人的武器
000:35 blue wolf 2 took 3 bomb from red dragon 2 in city 4
表示在0点35分,4号城市中,红魔1号武士wolf 抢走蓝魔2号武士dragon 3个bomb。为简单起见,武器不写复数形式
5) 报告战斗情况
战斗只有3种可能的输出结果:
000:40 red iceman 1 killed blue lion 12 in city 2 remaining 20 elements
表示在0点40分,1号城市中,红魔1号武士iceman 杀死蓝魔12号武士lion后,剩下生命值20
000:40 both red iceman 1 and blue lion 12 died in city 2
注意,把红武士写前面
000:40 both red iceman 1 and blue lion 12 were alive in city 2
注意,把红武士写前面
6) 武士欢呼
输出样例:003:40 blue dragon 2 yelled in city 4
7) 武士抵达敌军司令部
输出样例:001:10 red iceman 1 reached blue headquarter with 20 elements and force 30
(此时他生命值为20,攻击力为30)对于iceman,输出的生命值和攻击力应该是变化后的数值
8) 司令部被占领
输出样例:003:10 blue headquarter was taken
9)司令部报告生命元数量
000:50 100 elements in red headquarter
000:50 120 elements in blue headquarter
表示在0点50分,红方司令部有100个生命元,蓝方有120个
10)武士报告情况
000:55 blue wolf 2 has 2 sword 3 bomb 0 arrow and 7 elements
为简单起见,武器都不写复数形式。elements一律写复数,哪怕只有1个
交代武器情况时,次序依次是:sword,bomb, arrow。
输出事件时:
首先按时间顺序输出;
同一时间发生的事件,按发生地点从西向东依次输出. 武士前进的事件, 算是发生在目的地。
在一次战斗中有可能发生上面的 5 至 6 号事件。这些事件都算同时发生,其时间就是战斗开始时间。一次战斗中的这些事件,序号小的应该先输出。
两个武士同时抵达同一城市,则先输出红武士的前进事件,后输出蓝武士的。
对于同一城市,同一时间发生的事情,先输出红方的,后输出蓝方的。
显然,8号事件发生之前的一瞬间一定发生了7号事件。输出时,这两件事算同一时间发生,但是应先输出7号事件
虽然任何一方的司令部被占领之后,就不会有任何事情发生了。但和司令部被占领同时发生的事件,全都要输出。
#include
#include
#include
#include
#include
using namespace std;
//attention to initialize data for every test data
const string weap[3] = {"sword", "bomb", "arrow"};
int blue_ord[5] = {4,1,2,3,5}; //blue headquarter order: lion,dragon,ninja,iceman,wolf
int red_ord[5] = {3,4,5,2,1}; //red headquarter order: iceman,lion,wolf,ninja,dragon
int ini_life[6]; //lif[1~5] refers to initial life of dragon 、ninja、iceman、lion、wolf
int AttackForce[6]; //AttackForce for dragon 、ninja、iceman、lion、wolf
int LoyaltyDecrease; //loyalty decreasing every step for a lion
int Hour=0;
bool MainFlag=1; //judge whether a headquarter is taken
//standard form of time output
void show_hour() {
cout<0) return 0;
show_hour();
cout<<":05 "<redwarrior) {
if (leftCity->redwarrior->Name=="iceman") leftCity->redwarrior->Life-=(leftCity->redwarrior->Life)/10;
if (leftCity->redwarrior->Name=="lion") leftCity->redwarrior->LionMove();
show_hour();
if (!(destination->isHead)) {
cout<<":10 "<<"red "<redwarrior->Name<<" "<redwarrior->Number<<" marched to city "
<CityName<<" with "<redwarrior->Life<<" elements and force "
<redwarrior->Attack<isHead) {
cout<<":10 "<<"red "<redwarrior->Name<<" "<redwarrior->Number<<" reached blue headquarter with "
<redwarrior->Life<<" elements and force "<redwarrior->Attack<tempred = leftCity->redwarrior;
leftCity->redwarrior=NULL;
}
if (rightCity->bluewarrior) {
if (rightCity->bluewarrior->Name=="iceman") rightCity->bluewarrior->Life-=(rightCity->bluewarrior->Life)/10;
if (rightCity->bluewarrior->Name=="lion") rightCity->bluewarrior->LionMove();
show_hour();
if (!(destination->isHead)) {
cout<<":10 "<<"blue "<bluewarrior->Name<<" "<bluewarrior->Number<<" marched to city "
<CityName<<" with "<bluewarrior->Life<<" elements and force "
<bluewarrior->Attack<isHead) {
cout<<":10 "<<"blue "<bluewarrior->Name<<" "<bluewarrior->Number<<" reached red headquarter with "
<bluewarrior->Life<<" elements and force "<bluewarrior->Attack<tempblue = rightCity->bluewarrior;
rightCity->bluewarrior=NULL;
}
}
//all the warriors move in order
void allWarriorMove (City* cityArray, int start, int end) {
for (int i=start; i<=end; ++i) warriorMove(&cityArray[i], &cityArray[i-1], &cityArray[i+1]);
}
//move warriors to correct place in a city
void warriorPlace (City* destination) {
if (destination->tempblue) {
destination->bluewarrior=destination->tempblue;
destination->tempblue=NULL;
}
if (destination->tempred) {
destination->redwarrior=destination->tempred;
destination->tempred=NULL;
}
}
//wolf rob other enimie
void rob (City* city) {
if (city->redwarrior->Name!="wolf" && city->bluewarrior->Name!="wolf") return;
if (city->redwarrior->Name=="wolf" && city->bluewarrior->Name=="wolf") return;
if (city->redwarrior->Name=="wolf") {
if (city->redwarrior->weapons.SumWeap==10 || city->bluewarrior->weapons.SumWeap==0) return;
int i_=0;
for (i_=0; i_<3; i_++) {
if (city->bluewarrior->weapons.WeapNum[i_]>0) break;
}
int robNum = min (city->bluewarrior->weapons.WeapNum[i_], 10-city->redwarrior->weapons.SumWeap);
if (i_==2) {
if (city->bluewarrior->weapons.WeapNum[2] - city->bluewarrior->weapons.UsedArrow < robNum) {
int used_change=city->bluewarrior->weapons.UsedArrow-city->bluewarrior->weapons.WeapNum[2]+robNum;
city->bluewarrior->weapons.UsedArrow-=used_change;
city->redwarrior->weapons.UsedArrow+=used_change;
}
}
city->redwarrior->weapons.SumWeap+=robNum;
city->redwarrior->weapons.WeapNum[i_]+=robNum;
city->bluewarrior->weapons.WeapNum[i_]-=robNum;
city->bluewarrior->weapons.SumWeap-=robNum;
show_hour();
cout<<":35 "<<"red wolf "<redwarrior->Number<<" took "<bluewarrior->Name<<" "<bluewarrior->Number<<" in city "<CityName<bluewarrior->Name=="wolf") {
if (city->bluewarrior->weapons.SumWeap==10 || city->redwarrior->weapons.SumWeap==0) return;
int i_=0;
for (i_=0; i_<3; i_++) {
if (city->redwarrior->weapons.WeapNum[i_]>0) break;
}
int robNum = min (city->redwarrior->weapons.WeapNum[i_], 10-city->bluewarrior->weapons.SumWeap);
if (i_==2) {
if (city->redwarrior->weapons.WeapNum[2] - city->redwarrior->weapons.UsedArrow < robNum) {
int used_change=city->redwarrior->weapons.UsedArrow-city->redwarrior->weapons.WeapNum[2]+robNum;
city->redwarrior->weapons.UsedArrow-=used_change;
city->bluewarrior->weapons.UsedArrow+=used_change;
}
}
city->bluewarrior->weapons.SumWeap+=robNum;
city->bluewarrior->weapons.WeapNum[i_]+=robNum;
city->redwarrior->weapons.WeapNum[i_]-=robNum;
city->redwarrior->weapons.SumWeap-=robNum;
show_hour();
cout<<":35 "<<"blue wolf "<bluewarrior->Number<<" took "<redwarrior->Name<<" "<redwarrior->Number<<" in city "<CityName<Life-=(attacker->Attack)/5;
break;
}
case 1: {
another->Life-=(attacker->Attack)*2/5;
if (attacker->Name!="ninja") attacker->Life-=(attacker->Attack)/5;
attacker->weapons.SumWeap--;
attacker->weapons.WeapNum[1]--;
break;
}
case 2: {
another->Life-=(attacker->Attack)*3/10;
if (attacker->weapons.UsedArrow>0) {
attacker->weapons.UsedArrow--;
attacker->weapons.WeapNum[2]--;
attacker->weapons.SumWeap--;
} else {
attacker->weapons.UsedArrow++;
}
break;
}
}
}
//capture after battle
void captureWeapon(warrior* &attacker, warrior* &another) {
int addw0=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[0]);
attacker->weapons.WeapNum[0]+=addw0;
attacker->weapons.SumWeap+=addw0;
int addw1=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[1]);
attacker->weapons.WeapNum[1]+=addw1;
attacker->weapons.SumWeap+=addw1;
int addw2=min(10-attacker->weapons.SumWeap, another->weapons.WeapNum[2]);
attacker->weapons.WeapNum[2]+=addw2;
attacker->weapons.SumWeap+=addw2;
if (addw2 > another->weapons.WeapNum[2]-another->weapons.UsedArrow)
attacker->weapons.UsedArrow+=(addw2-another->weapons.WeapNum[2]+another->weapons.UsedArrow);
}
//judge an one-time-attacking result
bool attackResult(City* city) {
if (city->redwarrior->Life<=0 && city->bluewarrior->Life<=0) {
show_hour();
cout<<":40 both red "<redwarrior->Name<<" "<redwarrior->Number<<" and blue "
<bluewarrior->Name<<" "<bluewarrior->Number<<" died in city "<CityName<bluewarrior;
city->bluewarrior=NULL;
delete city->redwarrior;
city->redwarrior=NULL;
return 1;
}
if (city->bluewarrior->Life<=0) {
captureWeapon(city->redwarrior, city->bluewarrior);
show_hour();
cout<<":40 red "<redwarrior->Name<<" "<redwarrior->Number<<" killed blue "
<bluewarrior->Name<<" "<bluewarrior->Number<<" in city "<CityName
<<" remaining "<redwarrior->Life<<" elements"<bluewarrior;
city->bluewarrior=NULL;
if(city->redwarrior->Name=="dragon") {
show_hour();
cout<<":40 "<redwarrior->Head<<" dragon "<redwarrior->Number<<" yelled in city "<CityName<redwarrior->Life<=0) {
captureWeapon(city->bluewarrior, city->redwarrior);
show_hour();
cout<<":40 blue "<bluewarrior->Name<<" "<bluewarrior->Number<<" killed red "
<redwarrior->Name<<" "<redwarrior->Number<<" in city "<CityName
<<" remaining "<bluewarrior->Life<<" elements"<redwarrior;
city->redwarrior=NULL;
if(city->bluewarrior->Name=="dragon") {
show_hour();
cout<<":40 "<bluewarrior->Head<<" dragon "<bluewarrior->Number<<" yelled in city "<CityName<redwarrior && city->bluewarrior)) return;
bool temp_flag=0;
int redlife=city->redwarrior->Life, redweap=city->redwarrior->weapons.SumWeap, reduarrow=city->redwarrior->weapons.UsedArrow,
bluelife=city->bluewarrior->Life, blueweap=city->bluewarrior->weapons.SumWeap, blueuarrow=city->bluewarrior->weapons.UsedArrow; //for judging a tie
int i_red=-1, i_blue=-1; //weapon
if (city_num%2==1) {
if (city->redwarrior->weapons.SumWeap) {
for (int i=1; i<=3; ++i) {
i_red++;
if (city->redwarrior->weapons.WeapNum[i_red%3]) break;
}
OneTimeAttack(city->redwarrior, city->bluewarrior, i_red%3);
if (attackResult(city)) return;
}
}
int tie_counter=0;
while (!temp_flag) {
redlife=city->redwarrior->Life;
redweap=city->redwarrior->weapons.SumWeap;
reduarrow=city->redwarrior->weapons.UsedArrow;
bluelife=city->bluewarrior->Life;
blueweap=city->bluewarrior->weapons.SumWeap;
blueuarrow=city->bluewarrior->weapons.UsedArrow;
if (city->bluewarrior->weapons.SumWeap) {
for (int i=1; i<=3; ++i) {
i_blue++;
if (city->bluewarrior->weapons.WeapNum[i_blue%3]) break;
}
OneTimeAttack(city->bluewarrior,city->redwarrior,i_blue%3);
if (attackResult(city)) return;
}
if (city->redwarrior->weapons.SumWeap) {
for (int i=1; i<=3; ++i) {
i_red++;
if (city->redwarrior->weapons.WeapNum[i_red%3]) break;
}
OneTimeAttack(city->redwarrior, city->bluewarrior, i_red%3);
if (attackResult(city)) return;
}
if (redlife==city->redwarrior->Life&& redweap==city->redwarrior->weapons.SumWeap&&reduarrow==city->redwarrior->weapons.UsedArrow&&
bluelife==city->bluewarrior->Life&& blueweap==city->bluewarrior->weapons.SumWeap&&blueuarrow==city->bluewarrior->weapons.UsedArrow) {
tie_counter++;
} else tie_counter=0;
if (tie_counter>=3) {
temp_flag=1;
break;
}
}
if (temp_flag) {
show_hour();
cout<<":40 both red "<redwarrior->Name<<" "<redwarrior->Number<<" and blue "
<bluewarrior->Name<<" "<bluewarrior->Number<<" were alive in city "<CityName<redwarrior->Name=="dragon") {
show_hour();
cout<<":40 "<redwarrior->Head<<" dragon "<redwarrior->Number<<" yelled in city "<CityName<bluewarrior->Name=="dragon") {
show_hour();
cout<<":40 "<bluewarrior->Head<<" dragon "<bluewarrior->Number<<" yelled in city "<CityName<redwarrior) {
show_hour();
cout<<":55 red "<redwarrior->Name<<" "<redwarrior->Number<<" has "
<redwarrior->weapons.WeapNum[0]<<" sword "
<redwarrior->weapons.WeapNum[1]<<" bomb "
<redwarrior->weapons.WeapNum[2]<<" arrow and "
<redwarrior->Life<<" elements"<bluewarrior) {
show_hour();
cout<<":55 blue "<bluewarrior->Name<<" "<bluewarrior->Number<<" has "
<bluewarrior->weapons.WeapNum[0]<<" sword "
<bluewarrior->weapons.WeapNum[1]<<" bomb "
<bluewarrior->weapons.WeapNum[2]<<" arrow and "
<bluewarrior->Life<<" elements"<> res;
return res;
}
//debug
void showWarrior (warrior* &pointer) {
cout<<"Name:"<Name<<" Head:"<Head<<" Number:"<Number<<" Life:"<Life<<" Attack:"<Attack<weapons.weap_show();
}
int main() {
int TestNumber;
cin>>TestNumber;
for (int cas=1; cas<=TestNumber; ++cas) {
Hour=0;
MainFlag=1;
int headLife, cityNumber, maxHour;
cin >> headLife >> cityNumber >> LoyaltyDecrease >> maxHour;
for (int i=1; i<=5; i++) cin>>ini_life[i];
for (int i=1; i<=5; i++) cin>>AttackForce[i];
Headquarter red("red", headLife, red_ord), blue("blue", headLife, blue_ord);
City* cities=new City [cityNumber+4];
for (int i=0; iLionEscape()) {
delete cities[i].redwarrior;
cities[i].redwarrior=NULL;
}
if (cities[i].bluewarrior&&cities[i].bluewarrior->LionEscape()) {
delete cities[i].bluewarrior;
cities[i].bluewarrior=NULL;
}
}
}
if ((Hour)*60+10<=maxHour) {
allWarriorMove(cities, 1, cityNumber+2);
for (int i=1; i<=cityNumber+2; ++i) warriorPlace(&cities[i]);
if (!MainFlag) break;
}
if ((Hour)*60+35<=maxHour) {
for (int i=1; i<=cityNumber+2; ++i) if (cities[i].bluewarrior&&cities[i].redwarrior) rob(&cities[i]);
}
if ((Hour)*60+40<=maxHour) {
for (int i=2; i<=cityNumber+1; ++i) Battling(&cities[i], i-1);
}
if ((Hour)*60+50<=maxHour)
headAnnounce(red,blue);
if ((Hour)*60+55<=maxHour)
for (int i=1; i<=cityNumber+2; ++i) warriorAnnounce(&cities[i]);
Hour++;
}
}
return 0;
}