魔兽世界之二:装备
魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。
红司令部,City 1,City 2,……,City n,蓝司令部
两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值这两种属性。
有的武士可以拥有武器。武器有三种,sword, bomb,和arrow,编号分别为0,1,2。
双方的武士编号都是从1开始计算。红方制造出来的第 n 个武士,编号就是n。同样,蓝方制造出来的第 n 个武士,编号也是n。
不同的武士有不同的特点。
dragon 可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。
ninja可以拥有两件武器。编号为n的ninja降生时即获得编号为 n%3 和 (n+1)%3的武器。
iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。
lion 有“忠诚度”这个属性,其值等于它降生后其司令部剩余生命元的数目。
wolf没特点。
请注意,在以后的题目里,武士的士气,生命值,忠诚度在其生存期间都可能发生变化,都有作用,武士手中的武器随着使用攻击力也会发生变化。
武士在刚降生的时候有一个生命值。
在每个整点,双方的司令部中各有一个武士降生。
红方司令部按照 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武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。
如果造出的是dragon,那么还要输出一行,例:
It has a arrow,and it's morale is 23.34
表示该dragon降生时得到了arrow,其士气是23.34(为简单起见,本题中arrow前面的冠词用a,不用an,士气精确到小数点后面2位,四舍五入)
如果造出的是ninja,那么还要输出一行,例:
It has a bomb and a arrow
表示该ninja降生时得到了bomb和arrow。
如果造出的是iceman,那么还要输出一行,例:
It has a sword
表示该iceman降生时得到了sword。
如果造出的是lion,那么还要输出一行,例:
It's loyalty is 24
表示该lion降生时的忠诚度是24。
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仅仅增加了武器装备等部分。为了后续版本编写的方便,这里定义了warrior类以及四个派生类。
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
const string weap[3]={"sword", "bomb", "arrow"};
int blue_ord[5]={4,1,2,3,5};
int red_ord[5]={3,4,5,2,1};
int lif[6]; //lif[1~5] refers to life of dragon 、ninja、iceman、lion、wolf
class warrior {
private:
const int life;
public:
warrior (int num=0): life(num) {}
void born () {
cout<<"born with strength "<<life;
}
};
class dragon : public warrior {
private:
int weapon;
double morale;
public:
dragon (int n1, int n2, double d): warrior(n1), weapon(n2), morale(d) {}
void dra_born () {
cout<<"It has a "<<weap[weapon]<<",and it's morale is ";
cout<<setiosflags(ios::fixed)<<setprecision(2)<<morale;
}
};
class ninja : public warrior {
private:
int weap1, weap2;
public:
ninja (int n1, int n2, int n3): warrior(n1), weap1(n2), weap2(n3) {}
void nin_born () {
cout<<"It has a "<<weap[weap1]<<" and a "<<weap[weap2];
}
};
class iceman : public warrior {
private:
int weap1;
public:
iceman (int n1, int n2): warrior(n1), weap1(n2) {}
void ice_born () {
cout<<"It has a "<<weap[weap1];
}
};
class lion : public warrior {
private:
int loyalty;
public:
lion (int n1, int n2): warrior(n1), loyalty(n2) {}
void lio_born () {
cout<<"It's loyalty is "<<loyalty;
}
};
//wolf has nothing special, so it's unnecessary to buid a wolf class.
class headquarter {
private:
const string name;
int lifeunit;
int war_num[6]; //war_num[0] refers to amount of warriors; war_num[i] (i>0) refers to number of each kind of warriors
int scanner;
int s_o[5]; //scan order
public:
bool pro_abl; //judge if the headquarter is able to produce warriors
headquarter(string s, int n, int ar[]): name(s), lifeunit(n), scanner(-1), pro_abl(1) {
for (int i=0; i<6; ++i) war_num[i]=0;
for (int i=0; i<5; ++i) s_o[i]=ar[i];
}
void producing ();
};
void headquarter::producing() {
if (!pro_abl) {
cout<<"error!"<<endl;
return;
}
int i_=7;
while (--i_) {
++scanner;
if ( lif[s_o[scanner%5]]<=lifeunit) break;
if (i_==1) {
cout<<name<<" headquarter stops making warriors"<<endl;
pro_abl=0;
return;
}
}
int res=s_o[scanner%5]; //producing result
switch (res) {
case 1: {
++war_num[0];
++war_num[1];
lifeunit-=lif[1];
dragon dra_(lif[1], war_num[0]%3, double(lifeunit)/double(lif[1]));
cout<<name<<" dragon "<<war_num[0]<<" ";
dra_.born();
cout<<","<<war_num[1]<<" dragon in "<<name<<" headquarter"<<endl;
dra_.dra_born(); cout<<endl;
break;
} /**dragon case.
example: 001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
It has a arrow,and it's morale is 3.67
**/
case 2: {
++war_num[0];
++war_num[2];
lifeunit-=lif[2];
ninja nin_(lif[2], war_num[0]%3, (war_num[0]+1)%3);
cout<<name<<" ninja "<<war_num[0]<<" ";
nin_.born();
cout<<","<<war_num[2]<<" ninja in "<<name<<" headquarter"<<endl;
nin_.nin_born(); cout<<endl;
break;
} /*** ninja case.
example: 002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
It has a sword and a bomb
***/
case 3: {
++war_num[0];
++war_num[3];
lifeunit-=lif[3];
iceman ice_(lif[3], war_num[0]%3);
cout<<name<<" iceman "<<war_num[0]<<" ";
ice_.born();
cout<<","<<war_num[3]<<" iceman in "<<name<<" headquarter"<<endl;
ice_.ice_born(); cout<<endl;
break;
} /*** iceman case.
example: 000 red iceman 1 born with strength 5,1 iceman in red headquarter
It has a bomb
***/
case 4: {
++war_num[0];
++war_num[4];
lifeunit-=lif[4];
lion lio_(lif[4], lifeunit);
cout<<name<<" lion "<<war_num[0]<<" ";
lio_.born();
cout<<","<<war_num[4]<<" lion in "<<name<<" headquarter"<<endl;
lio_.lio_born(); cout<<endl;
break;
} /****
lion case.
example: 000 blue lion 1 born with strength 6,1 lion in blue headquarter
It's loyalty is 14
***/
default: {
++war_num[0];
++war_num[5];
lifeunit-=lif[5];
warrior wol_(lif[5]);
cout<<name<<" wolf "<<war_num[0]<<" ";
wol_.born();
cout<<","<<war_num[5]<<" wolf in "<<name<<" headquarter"<<endl;
break;
} /****
wolf case.
example: 002 red wolf 3 born with strength 7,1 wolf in red headquarter
***/
}
}
int main () {
int Test_Number=0;
cin>>Test_Number;
for (int i_=1; i_<=Test_Number; ++i_) {
int Time=0;
int M=0;
cin>>M;
for (int i=1; i<=5; ++i) cin>>lif[i];
headquarter red("red", M, red_ord);
headquarter blue("blue", M, blue_ord);
cout<<"Case:"<<i_<<endl;
while (blue.pro_abl+red.pro_abl) {
if (red.pro_abl) {
cout<<setw(3)<<setfill('0')<<Time<<" ";
red.producing();
}
if (blue.pro_abl) {
cout<<setw(3)<<setfill('0')<<Time<<" ";
blue.producing();
}
++Time;
}
}
return 0;
}