编程作业--魔兽世界之二:装备

魔兽世界之二:装备

总时间限制: 

1000ms

内存限制: 

65536kB

描述

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。 

红司令部,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
20
3 4 5 6 7

样例输出

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
It has a bomb
000 blue lion 1 born with strength 6,1 lion in blue headquarter
It's loyalty is 14
001 red lion 2 born with strength 6,1 lion in red headquarter
It's loyalty is 9
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
It has a arrow,and it's morale is 3.67
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
It has a sword and a bomb
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
It has a bomb
004 blue headquarter stops making warriors

这个版本相比较上一个写的,稍微顺眼了一点......

 

代码:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string weapon[3] = { "sword","bomb","arrow" };
class warrior {
public:
	int n, hp, atk,flag;
	warrior(int n, int hp, int atk,int flag) {
		this->n = n;
		this->hp = hp;
		this->atk = atk;
		this->flag = flag;
	}
};

class dragon :public warrior {
public:
	static int r_number;
	static int b_number;
	double morale;
	vector<int> arms;
	dragon(int n_t, int hp_t, int atk_t, int flag_t,int life) :warrior(n_t, hp_t, atk_t,flag_t) {
		morale = double(life) / hp_t;
		if (flag == 0) {//0代表red一方 
			r_number++;
		}
		else {
			b_number++;
		}
		arms.push_back(n_t % 3);
	}
	void print() {
		if (flag == 0)
			printf("dragon %d born with strength %d,%d dragon in red headquarter\n", n, hp, r_number);
		else
			printf("dragon %d born with strength %d,%d dragon in blue headquarter\n", n, hp, b_number);
		cout << "It has a " << weapon[n % 3] << ",and it's morale is ";
		printf("%.2f\n", morale);

	}
};

class ninja :public warrior {
public:
	static int r_number;
	static int b_number;
	vector<int> arms;
	ninja(int n_t, int hp_t, int atk_t, int flag_t) :warrior(n_t, hp_t, atk_t, flag_t) {
		if (flag == 0) {//0代表red一方 
			r_number++;
		}
		else {
			b_number++;
		}
		arms.push_back(n_t % 3);
		arms.push_back((n_t + 1) % 3);

	}
	void print() {
		if (flag == 0)
			printf("ninja %d born with strength %d,%d ninja in red headquarter\n", n, hp, r_number);
		else
			printf("ninja %d born with strength %d,%d ninja in blue headquarter\n", n, hp, b_number);
		cout << "It has a " << weapon[n % 3] << " and a " << weapon[(n + 1) % 3] << endl;
	}
};

class iceman :public warrior {
public:
	static int r_number;
	static int b_number;
	vector<int> arms;
	iceman(int n_t, int hp_t, int atk_t, int flag_t) :warrior(n_t, hp_t, atk_t, flag_t) {
		flag = flag_t;
		if (flag == 0) {//0代表red一方 
			r_number++;
		}
		else {
			b_number++;
		}
		arms.push_back(n_t % 3);

	}
	void print() {
		if (flag == 0)
			printf("iceman %d born with strength %d,%d iceman in red headquarter\n", n, hp, r_number);
		else
			printf("iceman %d born with strength %d,%d iceman in blue headquarter\n", n, hp, b_number);
		cout << "It has a " << weapon[n % 3] << endl;
	}
};

class lion :public warrior {
public:
	static int r_number;
	static int b_number;
	int loyalty;
	//vector<int> arms;
	lion(int n_t, int hp_t, int atk_t, int flag_t,int life) :warrior(n_t, hp_t, atk_t, flag_t) {
		loyalty = life;
		if (flag == 0) {//0代表red一方 
			r_number++;
		}
		else {
			b_number++;
		}

	}
	void print() {
		if (flag == 0)
			printf("lion %d born with strength %d,%d lion in red headquarter\n", n, hp, r_number);
		else
			printf("lion %d born with strength %d,%d lion in blue headquarter\n", n, hp, b_number);
		cout << "It's loyalty is " << loyalty << endl;
	}
};

class wolf :public warrior {
public:
	static int r_number;
	static int b_number;
	//vector<int> arms;
	wolf(int n_t, int hp_t, int atk_t, int flag_t) :warrior(n_t, hp_t, atk_t, flag_t) {
		flag = flag_t;
		if (flag == 0) {//0代表red一方 
			r_number++;
		}
		else {
			b_number++;
		}

	}
	void print() {
		if (flag == 0)
			printf("wolf %d born with strength %d,%d wolf in red headquarter\n", n, hp, r_number);
		else
			printf("wolf %d born with strength %d,%d wolf in blue headquarter\n", n, hp, b_number);
	}
};

int dragon::r_number = 0;
int ninja::r_number = 0;
int iceman::r_number = 0;
int lion::r_number = 0;
int wolf::r_number = 0;

int dragon::b_number = 0;
int ninja::b_number = 0;
int iceman::b_number = 0;
int lion::b_number = 0;
int wolf::b_number = 0;

int main()
{
	int N;
	scanf("%d", &N);
	int cnt = 0;//case的编号
	while (N--) {
		int m;//生命值
		scanf("%d", &m);
		int d, n, i, l, w;//所需生命值
		scanf("%d %d %d %d %d", &d, &n, &i, &l, &w);
		int min_hp = min(d, min(n, min(i, min(l, w))));
		printf("Case:%d\n", ++cnt);
		dragon::r_number = 0;
		ninja::r_number = 0;
		iceman::r_number = 0;
		lion::r_number = 0;
		wolf::r_number = 0;
		dragon::b_number = 0;
		ninja::b_number = 0;
		iceman::b_number = 0;
		lion::b_number = 0;
		wolf::b_number = 0;
		int r = m, b = m;//双方剩余生命值
		int cnt_r = 0, cnt_b = 0;//整点时刻,+1就是武士的编号
		//vector<warrior> r_army, b_army;
		//int d_cnt = 0, n_cnt = 0, i_cnt = 0, l_cnt = 0, w_cnt = 0;//各种武士的编号
		int r_end = 0, b_end = 0;//等于1时,表示已经无法再生成了
		int r_i_ok = 0, r_l_ok = 0, r_w_ok = 0, r_n_ok = 0, r_d_ok = 0;//轮换生成
		int b_i_ok = 0, b_l_ok = 0, b_w_ok = 0, b_n_ok = 0, b_d_ok = 0;

		int r_ok = 0, b_ok = 0;//等于1时,说明已经生成了一个,等于0时说明还没生成,此时才可以生成
		while (1) {
			if (r_end == 1 && b_end == 1) break;//只有当无法生成时才跳出循环 
			r_ok = 0;
			b_ok = 0;
			if (r_ok == 0 && r >= min_hp && r_end == 0) {
				if (r_i_ok == 1 && r_l_ok == 1 && r_w_ok == 1 && r_n_ok == 1 && r_d_ok == 1) {
					r_i_ok = 0;
					r_l_ok = 0;
					r_w_ok = 0;
					r_n_ok = 0;
					r_d_ok = 0;
				}
				//解决bug:当所剩生命值,只够前面的小的,而不够后续的大的,将导致 x_x_ok的值一直为0,无法转移到上面的初始化为0的部分,此时小的也无法生成了
				if (r >= i && r_ok == 0 && r_i_ok == 0) {//iceman
					printf("%03d red ", cnt_r++);
					r -= i;
					iceman tmp(cnt_r, i, 0, 0);
					//r_army.push_back(tmp);
					tmp.print();
					r_ok = 1;
					r_i_ok = 1;
				}
				else if (r_i_ok == 0 && r < i) r_i_ok = 1;
				if (r >= l && r_ok == 0 && r_l_ok == 0) {//lion
					printf("%03d red ", cnt_r++);
					r -= l;
					lion tmp(cnt_r, l, 0, 0,r);
					//r_army.push_back(tmp);
					tmp.print();
					r_ok = 1;
					r_l_ok = 1;
				}
				else if (r_l_ok == 0 && r < l) r_l_ok = 1;
				if (r >= w && r_ok == 0 && r_w_ok == 0) {//wolf
					printf("%03d red ", cnt_r++);
					r -= w;
					wolf tmp(cnt_r, w, 0, 0);
					//r_army.push_back(tmp);
					tmp.print();
					r_ok = 1;
					r_w_ok = 1;
				}
				else if (r_w_ok == 0 && r < w) r_w_ok = 1;
				if (r >= n && r_ok == 0 && r_n_ok == 0) {//ninja
					printf("%03d red ", cnt_r++);
					r -= n;
					ninja tmp(cnt_r, n, 0, 0);
					//r_army.push_back(tmp);
					tmp.print();
					r_ok = 1;
					r_n_ok = 1;
				}
				else if (r_n_ok == 0 && r < n) r_n_ok = 1;
				if (r >= d && r_ok == 0 && r_d_ok == 0) {//dragon
					printf("%03d red ", cnt_r++);
					r -= d;
					dragon tmp(cnt_r, d, 0, 0,r);
					//r_army.push_back(tmp);
					tmp.print();
					r_ok = 1;
					r_d_ok = 1;
				}
				else if (r_d_ok == 0 && r < d) r_d_ok = 1;
			}
			else {
				if (r_end == 0) {
					printf("%03d red ", cnt_r++);
					printf("headquarter stops making warriors\n");
					r_end = 1;
				}
			}


			if (b_ok == 0 && b >= min_hp && b_end == 0) {
				if (r_ok == 0 && r_end == 0) continue;//red一方没有生成,且还有足够的生命元的话,此时blue一方也不能生成,需要下一轮重新遍历
				if (b_i_ok == 1 && b_l_ok == 1 && b_w_ok == 1 && b_n_ok == 1 && b_d_ok == 1) {
					b_i_ok = 0;
					b_l_ok = 0;
					b_w_ok = 0;
					b_n_ok = 0;
					b_d_ok = 0;
				}
				if (b >= l && b_ok == 0 && b_l_ok == 0) {//lion
					printf("%03d blue ", cnt_b++);
					b -= l;
					lion tmp(cnt_b, l, 0, 1,b);
					//r_army.push_back(tmp);
					tmp.print();
					b_ok = 1;
					b_l_ok = 1;
				}
				else if (b_l_ok == 0 && b < l) b_l_ok = 1;
				if (b >= d && b_ok == 0 && b_d_ok == 0) {//dragon
					printf("%03d blue ", cnt_b++);
					b -= d;
					dragon tmp(cnt_b, d, 0, 1,b);
					//r_army.push_back(tmp);
					tmp.print();
					b_ok = 1;
					b_d_ok = 1;
				}
				else if (b_d_ok == 0 && b < d) b_d_ok = 1;
				if (b >= n && b_ok == 0 && b_n_ok == 0) {//ninja
					printf("%03d blue ", cnt_b++);
					b -= n;
					ninja tmp(cnt_b, n, 0, 1);
					//r_army.push_back(tmp);
					tmp.print();
					b_ok = 1;
					b_n_ok = 1;
				}
				else if (b_n_ok == 0 && b < n) b_n_ok = 1;
				if (b >= i && b_ok == 0 && b_i_ok == 0) {//iceman
					printf("%03d blue ", cnt_b++);
					b -= i;
					iceman tmp(cnt_b, i, 0, 1);
					//r_army.push_back(tmp);
					tmp.print();
					b_ok = 1;
					b_i_ok = 1;
				}
				else if (b_i_ok == 0 && b < i) b_i_ok = 1;
				if (b >= w && b_ok == 0 && b_w_ok == 0) {//wolf
					printf("%03d blue ", cnt_b++);
					b -= w;
					wolf tmp(cnt_b, w, 0, 1);
					//r_army.push_back(tmp);
					tmp.print();
					b_ok = 1;
					b_w_ok = 1;
				}
				else if (b_w_ok == 0 && b < w) b_w_ok = 1;

			}
			else {
				if (b_end == 0) {
					printf("%03d blue ", cnt_b++);
					printf("headquarter stops making warriors\n");
					b_end = 1;
				}
			}
		}

	}
	return 0;
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值