记录编号 324170 评测结果 AAAAAAAAAA
题目名称 [HZOI 2015] 魔兽世界-终极版 最终得分 100
用户昵称 Gravatar小e 是否通过 通过
代码语言 C++ 运行时间 0.037 s
提交时间 2016-10-17 20:26:19 内存使用 0.31 MiB
显示代码纯文本
#include "cstdio"
#include "vector"

#define red 0
#define blue 1
#define None -1
#define iceman 0
#define lion 1
#define wolf 2
#define ninja 3
#define dragon 4
#define sword 0
#define bomb 1
#define arrow 2
#define initiative 1
#define passive 0
const int order[2][6] = {{iceman, lion, wolf, ninja, dragon}, {lion, dragon, ninja, iceman, wolf}};
const int loop_part = 5, minutes_per_hour = 60;
const int time_of_born = 0, time_of_escape = 5, time_of_march = 10, time_of_produce = 20, time_of_earn = 30, time_of_shoot = 35, time_of_bomb = 38, time_of_fight = 40, time_of_report_for_element = 50, time_of_report_for_arms = 55;
const double eps = 1e-8;
const char name_table[5][10] = {"iceman", "lion", "wolf", "ninja", "dragon"}, weapon_table[3][10] = {"sword", "bomb", "arrow"};
int element_num_when_born[6], atk_when_born[6];
int Globle_hour, Globle_minute, Globle_clock; // 时 分 总时间
int first_element, num_of_city, atk_of_arrow, dec_of_loyalty, end_of_time;// 司令部初始生命元数 城市数 arrow攻击力 lion忠诚度下降值
int winner = None;

struct Weapon
{
	int type;// 武器的种类
	int sharpness;// sword的锋利度
	int last;// arrow的剩余次数

	inline Weapon(const int& a, const int& b) { type = a; sharpness = b; last = 0; }

	inline Weapon(const int& a)
	{
		type = a; sharpness = 0;
		if (a == arrow) last = 3;
		else last = 0;
	}

	inline Weapon() { type = None; sharpness = None; last = None; }
};

struct Soldier
{
	int id;// 编号
	int soldier_type;// 武士的种类
	int HP; // 生命值
	int atk; // 攻击力
	int loyalty;// lion忠诚度
	double morale;// dragon士气
	std::vector<Weapon> arms;// 武器

	inline void Init() { id = None; soldier_type = None; HP = None; atk = None; loyalty = None; morale = 0.0; arms.clear(); }
};

struct HeadQuarter
{
	//蓝方司令部位置在num_of_city + 1, 红方司令部在0
	int camp;// 阵营
	int element_num;// 生命元数量
	int tot;// 将产生的武士的编号
	int born_id;// 将产生的武士的种类
	Soldier new_comer;// 产生但还留在司令部中的武士
	std::vector<Soldier> enemies; // 司令部中的敌人

	inline void Init(const int& a) { camp = a; tot = 0; element_num = first_element; born_id = 0; new_comer.Init(); enemies.clear(); }

	inline void Born()// output not finished ************************************************************************************************************************************************************************************************************
	{
		new_comer.Init();
		if (element_num < element_num_when_born[order[camp][born_id]]) return;
		element_num -= element_num_when_born[order[camp][born_id]];
		new_comer.id = ++tot;
		new_comer.HP = element_num_when_born[order[camp][born_id]];
		new_comer.soldier_type = order[camp][born_id];
		new_comer.atk = atk_when_born[order[camp][born_id]];
		switch(order[camp][born_id]) {
			case iceman: {
				int weapon_id = new_comer.id % 3;
				if (weapon_id == sword) new_comer.arms.push_back(Weapon(weapon_id, atk_when_born[order[camp][born_id]] / 5));
				else new_comer.arms.push_back(Weapon(weapon_id));
				break;
			}
			case lion: {
				new_comer.loyalty = element_num;
				break;
			}
			case wolf: break;
			case ninja: {
				int weapon_id = new_comer.id % 3;
				if (weapon_id == sword) new_comer.arms.push_back(Weapon(weapon_id, atk_when_born[order[camp][born_id]] / 5));
				else new_comer.arms.push_back(Weapon(weapon_id));
				weapon_id = (new_comer.id + 1) % 3;
				if (weapon_id == sword) new_comer.arms.push_back(Weapon(weapon_id, atk_when_born[order[camp][born_id]] / 5));
				else new_comer.arms.push_back(Weapon(weapon_id));
				break;
			}
			case dragon: {
				new_comer.morale = (double)element_num / (double)new_comer.HP;
				int weapon_id = new_comer.id % 3;
				if (weapon_id == sword) new_comer.arms.push_back(Weapon(weapon_id, atk_when_born[order[camp][born_id]] / 5));
				else new_comer.arms.push_back(Weapon(weapon_id));
				break;
			}
		}
		if (camp == red) {
			printf("%03d:%02d red %s %d born\n", Globle_hour, Globle_minute, name_table[new_comer.soldier_type], new_comer.id);
			if (new_comer.soldier_type == dragon) printf("Its morale is %.2lf\n", new_comer.morale);
			if (new_comer.soldier_type == lion) printf("Its loyalty is %d\n", new_comer.loyalty);
		}
		else {
			printf("%03d:%02d blue %s %d born\n", Globle_hour, Globle_minute, name_table[new_comer.soldier_type], new_comer.id);
			if (new_comer.soldier_type == dragon) printf("Its morale is %.2lf\n", new_comer.morale);
			if (new_comer.soldier_type == lion) printf("Its loyalty is %d\n", new_comer.loyalty);
		}
		born_id++;
		born_id %= loop_part;
	}	
}headquarters[2];

struct City
{
	int location; // 位置
	int last_win;// 上一次的的胜利者
	int flag;// 旗帜的状态
	int element_num;// 生命元数量
	Soldier quarter[2];// 城市中驻扎的红蓝武士编号

	inline void Init(const int a) { location = a; last_win = None; flag = None; element_num = 0; quarter[red].Init(); quarter[blue].Init(); }// 应该注意Init()的初始值
}cities[25];

inline void Escape()// pay attention to the cities ans the headquarters**********************************************************************************************************************************************************************************
{
	if (headquarters[red].new_comer.soldier_type == lion && headquarters[red].new_comer.loyalty <= 0){
		printf("%03d:%02d red lion %d ran away\n", Globle_hour, Globle_minute, headquarters[red].new_comer.id);
		headquarters[red].new_comer.Init();
	}
	for (int i = 1; i <= num_of_city; ++i){
		if (cities[i].quarter[red].soldier_type == lion && cities[i].quarter[red].loyalty <= 0){
			printf("%03d:%02d red lion %d ran away\n", Globle_hour, Globle_minute, cities[i].quarter[red].id);
			cities[i].quarter[red].Init();
		}
		if (cities[i].quarter[blue].soldier_type == lion && cities[i].quarter[blue].loyalty <= 0){
			printf("%03d:%02d blue lion %d ran away\n", Globle_hour, Globle_minute, cities[i].quarter[blue].id);
			cities[i].quarter[blue].Init();
		}
	}
	if (headquarters[blue].new_comer.soldier_type == lion && headquarters[blue].new_comer.loyalty <= 0){
		printf("%03d:%02d blue lion %d ran away\n", Globle_hour, Globle_minute, headquarters[blue].new_comer.id);
		headquarters[blue].new_comer.Init();
	}
	// 考虑lion在司令部中逃跑的情况
}

inline void Debuff_of_Iceman(Soldier& a)
{
	a.HP -= 9;
	if (a.HP <= 0) a.HP = 1;
	a.atk += 20;
}

inline void March()// pay attention to the cities and the headquarters***********************************************************************************************************************************************************************************
{
	// 红方向编号大的城市前进, 蓝方向编号小的前进
	// 考虑iceman的状态变化
	// 注意输出顺序
	cities[0].Init(0); cities[num_of_city+1].Init(num_of_city+1);
	cities[0].quarter[red] = headquarters[red].new_comer;
	cities[num_of_city+1].quarter[blue] = headquarters[blue].new_comer;
	//把红方总部当成0号城市, 蓝方总部当成(num_of_city + 1)号城市
	
	for (int i = num_of_city + 1; i; --i) {
		cities[i].quarter[red] = cities[i-1].quarter[red]; cities[i-1].quarter[red].Init();
		if (cities[i].quarter[red].soldier_type == iceman && i % 2 == 0) Debuff_of_Iceman(cities[i].quarter[red]);
	}
	for (int i = 0; i <= num_of_city; ++i) {
		cities[i].quarter[blue] = cities[i+1].quarter[blue]; cities[i+1].quarter[blue].Init();
		if (cities[i].quarter[blue].soldier_type == iceman && i % 2 == (num_of_city + 1) % 2) Debuff_of_Iceman(cities[i].quarter[blue]);
	}

	if (cities[0].quarter[blue].soldier_type != None) {// 蓝方武士到达红方司令部
		headquarters[red].enemies.push_back(cities[0].quarter[blue]);
		printf("%03d:%02d blue %s %d reached red headquarter with %d elements and force %d\n", Globle_hour, Globle_minute, name_table[cities[0].quarter[blue].soldier_type], cities[0].quarter[blue].id, cities[0].quarter[blue].HP, cities[0].quarter[blue].atk);
		if (headquarters[red].enemies.size() >= 2){
			winner = blue;
			printf("%03d:%02d red headquarter was taken\n", Globle_hour, Globle_minute);
		}	
	}
	for (int i = 1; i <= num_of_city; ++i) {
		if (cities[i].quarter[red].soldier_type != None)	
			printf("%03d:%02d red %s %d marched to city %d with %d elements and force %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, i, cities[i].quarter[red].HP, cities[i].quarter[red].atk);
		if (cities[i].quarter[blue].soldier_type != None)
			printf("%03d:%02d blue %s %d marched to city %d with %d elements and force %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, i, cities[i].quarter[blue].HP, cities[i].quarter[blue].atk);
	}
	if (cities[num_of_city+1].quarter[red].soldier_type != None) {
		headquarters[blue].enemies.push_back(cities[num_of_city+1].quarter[red]);
		printf("%03d:%02d red %s %d reached blue headquarter with %d elements and force %d\n", Globle_hour, Globle_minute,  name_table[cities[num_of_city+1].quarter[red].soldier_type], cities[num_of_city+1].quarter[red].id, cities[num_of_city+1].quarter[red].HP, cities[num_of_city+1].quarter[red].atk);
		if (headquarters[blue].enemies.size() >= 2){
			winner = red;
			printf("%03d:%02d blue headquarter was taken\n", Globle_hour, Globle_minute);
		}			
	}
	cities[0].Init(0); cities[num_of_city+1].Init(num_of_city+1);
}

inline void Produce()
{
	for (int i = 1; i <= num_of_city; ++i)
		cities[i].element_num += 10;
}

inline void Earn()// pay attention to the output*********************************************************************************************************************************************************************************************************
{
	for (int i = 1; i <= num_of_city; ++i) {
		if (cities[i].quarter[red].soldier_type != None && cities[i].quarter[blue].soldier_type == None){
			headquarters[red].element_num += cities[i].element_num;
			printf("%03d:%02d red %s %d earned %d elements for his headquarter\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, cities[i].element_num);
			cities[i].element_num = 0;
		}
		if (cities[i].quarter[blue].soldier_type != None && cities[i].quarter[red].soldier_type == None){
			headquarters[blue].element_num += cities[i].element_num;
			printf("%03d:%02d blue %s %d earned %d elements for his headquarter\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, cities[i].element_num);
			cities[i].element_num = 0;
		}
	}
}

inline void Shoot()// pay attention to the output and the variable***************************************************************************************************************************************************************************************
{
	// 考虑双方同时放箭, 彼此射杀的情况
	// 考虑对城市旗帜的影响
	for (int i = 1; i <= num_of_city; ++i) {
		if (i + 1 <= num_of_city && cities[i].quarter[red].soldier_type != None && cities[i+1].quarter[blue].soldier_type != None)// 红方武士只能射击下一个位置的敌人
			for (std::vector<Weapon>::iterator it = cities[i].quarter[red].arms.begin(); it != cities[i].quarter[red].arms.end(); ++it)
				if ((*it).type == arrow && (*it).last) {
					(*it).last--;
					if ((*it).last <= 0) cities[i].quarter[red].arms.erase(it);// 弓箭用完后, 从vector中除去
					cities[i+1].quarter[blue].HP -= atk_of_arrow;
					if (cities[i+1].quarter[blue].HP > 0) printf("%03d:%02d red %s %d shot\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id);// 未射杀敌人
					else {// 敌人被射杀
						printf("%03d:%02d red %s %d shot and killed blue %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, name_table[cities[i+1].quarter[blue].soldier_type], cities[i+1].quarter[blue].id);
						// cities[i+1].quarter[blue].Init(); **********注意被射杀的效果要放到Fight()中去处理, 因为Fight()的效果与Shoot()有关
					}
					break;
				}
		if (i - 1 && cities[i].quarter[blue].soldier_type != None && cities[i-1].quarter[red].soldier_type != None)
			for (std::vector<Weapon>::iterator it = cities[i].quarter[blue].arms.begin(); it != cities[i].quarter[blue].arms.end(); ++it)
				if ((*it).type == arrow && (*it).last) {
					(*it).last--;
					if ((*it).last <= 0) cities[i].quarter[blue].arms.erase(it);
					cities[i-1].quarter[red].HP -= atk_of_arrow;
					if (cities[i-1].quarter[red].HP > 0) printf("%03d:%02d blue %s %d shot\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id);
					else
						printf("%03d:%02d blue %s %d shot and killed red %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, name_table[cities[i-1].quarter[red].soldier_type], cities[i-1].quarter[red].id);
					break;
				}
	}
}

inline int Total_Atk(Soldier a, const int& type)// 用type判断a是主动攻击还是反击
{
	int ret;
	if(type == initiative) ret = a.atk;
	else ret = a.atk / 2;
	for (std::vector<Weapon>::iterator it = a.arms.begin(); it != a.arms.end(); ++it)
		if((*it).type == sword) { ret += (*it).sharpness; break; }
	return ret;
}

inline void Dull(Soldier& a)//如果有sword, sword变钝
{
	for (std::vector<Weapon>::iterator it = a.arms.begin(); it != a.arms.end(); ++it) 
		if ((*it).type == sword) {
			(*it).sharpness = (*it).sharpness * 4 / 5;
			if ((*it).sharpness <= 0) a.arms.erase(it);
			break;
		}
}

inline void Bomb()// pay attention to the loop and the camp**********************************************************************************************************************************************************************************************
{
	// 不会判断自己是否会被弓箭射杀
	// 事实上不可能出现双方互相使用Bomb的情况
	for (int i = 1; i <= num_of_city; ++i) {
		if (cities[i].quarter[red].HP > 0 && cities[i].quarter[blue].HP > 0 && cities[i].quarter[red].soldier_type != None && cities[i].quarter[blue].soldier_type != None) {
			if (cities[i].flag == red || (cities[i].flag == None && i % 2)) {// 红方先手, 要么红方判断自己被反杀而使用bomb, 要么蓝方判断自己被击杀而使用bomb
				for (std::vector<Weapon>::iterator it = cities[i].quarter[red].arms.begin(); it != cities[i].quarter[red].arms.end(); ++it) {
					if ((*it).type == bomb) {// 红方有bomb, 被蓝方反杀时才使用(前提是红方主动攻击杀不死蓝方)
						if (cities[i].quarter[blue].soldier_type != ninja && Total_Atk(cities[i].quarter[red], initiative) < cities[i].quarter[blue].HP && Total_Atk(cities[i].quarter[blue], passive) >= cities[i].quarter[red].HP) {// 红方判定要使用bomb
							printf("%03d:%02d red %s %d used a bomb and killed blue %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id);
							cities[i].quarter[blue].Init();
							cities[i].quarter[red].Init();
						}
						break;
					}
				}
				for (std::vector<Weapon>::iterator it = cities[i].quarter[blue].arms.begin(); it != cities[i].quarter[blue].arms.end(); ++it) {
					if ((*it).type == bomb) {// 蓝方有bomb, 被红方击杀时才使用
						if (Total_Atk(cities[i].quarter[red], initiative) >= cities[i].quarter[blue].HP) {// 蓝方判定要使用bomb
							printf("%03d:%02d blue %s %d used a bomb and killed red %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id);
							cities[i].quarter[blue].Init();
							cities[i].quarter[red].Init();
						}
						break;
					}
				}
			}
			else if (cities[i].flag == blue || (cities[i].flag == None && i % 2 == 0)) {// 蓝方先手, 要么蓝方判断自己被反杀而使用bomb, 要么红方判断自己被击杀而使用bomb
				for (std::vector<Weapon>::iterator it = cities[i].quarter[blue].arms.begin(); it != cities[i].quarter[blue].arms.end(); ++it) {
					if ((*it).type == bomb) {// 蓝方有bomb, 若自己被反杀则使用
						if (cities[i].quarter[red].soldier_type != ninja && Total_Atk(cities[i].quarter[blue], initiative) < cities[i].quarter[red].HP && Total_Atk(cities[i].quarter[red], passive) >= cities[i].quarter[blue].HP) {
							printf("%03d:%02d blue %s %d used a bomb and killed red %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id);
							cities[i].quarter[blue].Init();
							cities[i].quarter[red].Init();
						}
						break;
					}
				}
				for (std::vector<Weapon>::iterator it = cities[i].quarter[red].arms.begin(); it != cities[i].quarter[red].arms.end(); ++it) {
					if ((*it).type == bomb) {// 红方有bomb, 若自己被击杀则使用
						if (Total_Atk(cities[i].quarter[blue], initiative) >= cities[i].quarter[red].HP) {
							printf("%03d:%02d red %s %d used a bomb and killed blue %s %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id);
							cities[i].quarter[blue].Init();
							cities[i].quarter[red].Init();
						}
						break;
					}
				}
			}
		}
	}
}

inline void Debuff_of_Lion(Soldier& attacker, Soldier& victim)// lion作为victim, 生命值转移给对方武士
{
	if (victim.soldier_type == lion)
		attacker.HP += victim.HP;
}

inline void Debuff_of_Lion(Soldier& attacker)// lion作为attacker, 没有杀死敌人, 忠诚度下降
{
	if (attacker.soldier_type == lion)
		attacker.loyalty -= dec_of_loyalty;
}

inline void Buff_of_Dragon(Soldier& attacker, Soldier& victim, const int& pos, const int& type, const int& camp)// dragon作为attacker, type为主动则进行士气增加和欢呼动作
{
	if (attacker.soldier_type != dragon) return;
	if (victim.HP > 0) attacker.morale -= 0.2;
	if (victim.HP <= 0) attacker.morale += 0.2;
	if (type == initiative && attacker.morale - 0.8 > eps){// 只有主动杀死敌人后才欢呼
		if(camp == red) 
			printf("%03d:%02d red dragon %d yelled in city %d\n", Globle_hour, Globle_minute, attacker.id, pos);
		else
			printf("%03d:%02d blue dragon %d yelled in city %d\n", Globle_hour, Globle_minute, attacker.id, pos);
	}
}

inline void Buff_of_Wolf(Soldier& attacker, Soldier& victim)// wolf进行缴械
{
	if (attacker.soldier_type != wolf) return;
	bool had_already[5] = {0};// 记录wolf已有的武器
	for (std::vector<Weapon>::iterator it = attacker.arms.begin(); it != attacker.arms.end(); ++it)
		had_already[(*it).type] = 1;
	for (std::vector<Weapon>::iterator it = victim.arms.begin(); it != victim.arms.end(); ++it)// 找到wolf没有的武器并缴获
		if(!had_already[(*it).type]) attacker.arms.push_back(*it);
}

inline void Get_Element(City& pos, const int& camp)// camp一方获取城市pos的生命元
{
	if(camp == red)
		printf("%03d:%02d red %s %d earned %d elements for his headquarter\n", Globle_hour, Globle_minute, name_table[pos.quarter[red].soldier_type], pos.quarter[red].id, pos.element_num);
	else
		 printf("%03d:%02d blue %s %d earned %d elements for his headquarter\n", Globle_hour, Globle_minute, name_table[pos.quarter[blue].soldier_type], pos.quarter[blue].id, pos.element_num);
	headquarters[camp].element_num += pos.element_num;
	pos.element_num = 0;
}

inline void Reward(Soldier& attacker, const int& camp)// 司令部的奖励
{
	if (headquarters[camp].element_num >= 8) {
		headquarters[camp].element_num -= 8;
		attacker.HP += 8;
	}
}

inline void Flag_Change(const int& camp, City& pos)// 获胜方处理旗帜情况
{
	if (camp == None) { pos.last_win = None; return; }
	if (pos.last_win != camp) { pos.last_win = camp; return; }
	if (pos.last_win == camp) {
		if (pos.flag == camp) return;
		pos.flag = camp;
		if(camp == blue)
			printf("%03d:%02d blue flag raised in city %d\n", Globle_hour, Globle_minute, pos.location);
		else
			printf("%03d:%02d red flag raised in city %d\n", Globle_hour, Globle_minute, pos.location);
		return;
	}
}

inline void Fight()// error in varible of camp!!!!!******************************************************************************************************************************************************************************************************
{
	// 注意先手
	// 注意武器使用度的变化, 反击, 士气的变化, 忠诚度的变化, 欢呼, 敌人的死亡, lion特殊效果, 缴械, 生命元的取得, 总部的奖励, 旗帜的变化**...
	// ninja 不反击
	bool red_win[25] = {0};// 记录红方在哪个城市杀死了敌人, 总部奖励时用
	for (int i = 1; i <= num_of_city; ++i) {
		if (cities[i].quarter[red].soldier_type == None || cities[i].quarter[blue].soldier_type == None)// 城市中只有一个人, 不会发生战斗
			continue;
		if (cities[i].quarter[red].HP <= 0 && cities[i].quarter[blue].HP <= 0) {// 双方都在之前死亡
			cities[i].quarter[red].Init(); 
			cities[i].quarter[blue].Init(); 
			continue;
		}

		if (cities[i].quarter[red].HP > 0 && cities[i].quarter[blue].HP <= 0) {// 这应该是蓝方被箭射死的情况
			Buff_of_Wolf(cities[i].quarter[red], cities[i].quarter[blue]);
			if ((cities[i].flag == red || (cities[i].flag == None && i % 2))) Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, initiative, red);// dragin判断自己主动攻击
			Get_Element(cities[i], red);
			red_win[i] = 1;
			Flag_Change(red, cities[i]);
			cities[i].quarter[blue].Init();
			continue;
		}

		if (cities[i].quarter[blue].HP > 0 && cities[i].quarter[red].HP <= 0) {// 这应该是红方被箭射死的情况
			Buff_of_Wolf(cities[i].quarter[blue], cities[i].quarter[red]);
			if ((cities[i].flag == blue || (cities[i].flag == None && i % 2 == 0))) Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, initiative, blue);
			Get_Element(cities[i], blue);
			Reward(cities[i].quarter[blue], blue);
			Flag_Change(blue, cities[i]);
			cities[i].quarter[red].Init();
			continue;
		}

		if (cities[i].quarter[blue].HP > 0 && cities[i].quarter[red].HP > 0 && (cities[i].flag == red || (cities[i].flag == None && i % 2))) {// 双方在城市中交锋, 红方先手
			printf("%03d:%02d red %s %d attacked blue %s %d in city %d with %d elements and force %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, i, cities[i].quarter[red].HP, cities[i].quarter[red].atk);
			int red_atk = Total_Atk(cities[i].quarter[red], initiative);
			Dull(cities[i].quarter[red]);// 如果有剑, 就会用钝
			if (cities[i].quarter[blue].HP - red_atk <= 0) {// 蓝方被击杀, 红方胜利, 因为lion的存在, 生命值不能立即减少
				printf("%03d:%02d blue %s %d was killed in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, i);
				Debuff_of_Lion(cities[i].quarter[red], cities[i].quarter[blue]);// 如果蓝方是lion, lion生命值转移给红方武士
				cities[i].quarter[blue].HP -= red_atk;
				Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, initiative, red);// dragon作为attacker进行士气增减和欢呼动作
				Buff_of_Wolf(cities[i].quarter[red], cities[i].quarter[blue]);// wolf进行缴械
				Get_Element(cities[i], red); // 红方获取城市生命元
				red_win[i] = 1;// 记录红方在这个城市取得胜利, 司令部奖励用
				Flag_Change(red, cities[i]);// 旗帜
				cities[i].quarter[blue].Init();// 蓝方死亡, 移除	
			}
			else if(cities[i].quarter[blue].soldier_type != ninja) {// 蓝方未被击杀, 反击红方, ninja不反击
				cities[i].quarter[blue].HP -= red_atk;// 先把生命力降低
				Debuff_of_Lion(cities[i].quarter[red]);// 若红方为lion, 则忠诚度下降
				printf("%03d:%02d blue %s %d fought back against red %s %d in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, i);
				int blue_atk = Total_Atk(cities[i].quarter[blue], passive);
				Dull(cities[i].quarter[blue]);// 如果有剑, 就会用钝
				if (cities[i].quarter[red].HP - blue_atk <= 0) {//红方被反杀, 蓝方胜利
					printf("%03d:%02d red %s %d was killed in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, i);
					Debuff_of_Lion(cities[i].quarter[blue], cities[i].quarter[red]);// 如果红方是lion, lion生命值转移给蓝方武士
					cities[i].quarter[red].HP -= blue_atk;//drogon的特殊效果与敌人生命值的变化应该联系紧密
					Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, passive, blue);	
					Buff_of_Wolf(cities[i].quarter[blue], cities[i].quarter[red]);//蓝方wolf缴械
					Get_Element(cities[i], blue);//蓝方获取生命元
					Flag_Change(blue, cities[i]);// 旗帜
					Reward(cities[i].quarter[blue], blue);// 蓝方胜利, 直接奖励
					cities[i].quarter[red].Init();// 红方移除
				}
				else {// 红方没有被反杀, 扣减生命, 算是平局
					cities[i].quarter[red].HP -= blue_atk;
					Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, initiative, red);
					Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, passive, blue);
					Flag_Change(None, cities[i]);
				} 
			}
			else {// 蓝方是ninja
				cities[i].quarter[blue].HP -= red_atk;
				Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, initiative, red);
				if (cities[i].quarter[blue].HP <= 0) {
					Flag_Change(red, cities[i]);// 旗帜
					cities[i].quarter[blue].Init();
				}
				else Flag_Change(None, cities[i]);
			}
		}
		
		else if (cities[i].quarter[blue].HP > 0  && cities[i].quarter[red].HP > 0 && (cities[i].flag == blue || (cities[i].flag == None && i % 2 == 0))) {// 蓝方主动攻击
			printf("%03d:%02d blue %s %d attacked red %s %d in city %d with %d elements and force %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, i, cities[i].quarter[blue].HP, cities[i].quarter[blue].atk);
			int blue_atk = Total_Atk(cities[i].quarter[blue], initiative);// 蓝方主动攻击
			Dull(cities[i].quarter[blue]);// 如果有剑, 就会用钝
			if (cities[i].quarter[red].HP - blue_atk <= 0) {// 红方被击杀, 蓝方胜利
				printf("%03d:%02d red %s %d was killed in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, i);
				Debuff_of_Lion(cities[i].quarter[blue], cities[i].quarter[red]);// 如果红方是lion, 则生命值转移到蓝方
				cities[i].quarter[red].HP -= blue_atk;
				Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, initiative, blue);//dragon的效果
				Buff_of_Wolf(cities[i].quarter[blue], cities[i].quarter[red]);//缴械
				Get_Element(cities[i], blue);// 蓝方取得生命元
				Flag_Change(blue, cities[i]);// 旗帜
				Reward(cities[i].quarter[blue], blue);// 蓝方直接奖励
				cities[i].quarter[red].Init();// 红方移除
			}
			else if (cities[i].quarter[red].soldier_type != ninja) {// 红方反击
				cities[i].quarter[red].HP -= blue_atk;// 扣减生命
				Debuff_of_Lion(cities[i].quarter[blue]);// 若蓝方是lion, 则忠诚度下降
				printf("%03d:%02d red %s %d fought back against blue %s %d in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[red].soldier_type], cities[i].quarter[red].id, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, i);
				int red_atk = Total_Atk(cities[i].quarter[red], passive);
				Dull(cities[i].quarter[red]);
				if (cities[i].quarter[blue].HP - red_atk <= 0) {// 蓝方被反杀, 红方胜利
					printf("%03d:%02d blue %s %d was killed in city %d\n", Globle_hour, Globle_minute, name_table[cities[i].quarter[blue].soldier_type], cities[i].quarter[blue].id, i);
					Debuff_of_Lion(cities[i].quarter[red], cities[i].quarter[blue]);// 如果蓝方是lion, 则生命转移
					cities[i].quarter[blue].HP -= red_atk;
					Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, passive, red);// dragon
					Buff_of_Wolf(cities[i].quarter[red], cities[i].quarter[blue]);// 缴械
					Get_Element(cities[i], red);// 红方获取生命元
					Flag_Change(red, cities[i]);// 旗帜偏向红方
					red_win[i] = 1;// 记录红方胜利
					cities[i].quarter[blue].Init();// 蓝方移除
				}
				else {// 未被反杀, 平局
					cities[i].quarter[blue].HP -= red_atk;// 蓝方未被反杀, 生命扣减
					Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, initiative, blue);
					Buff_of_Dragon(cities[i].quarter[red], cities[i].quarter[blue], i, passive, red);
					Flag_Change(None, cities[i]);
				}
			}
			else {
				cities[i].quarter[red].HP -= blue_atk;// 红方是ninja
				Buff_of_Dragon(cities[i].quarter[blue], cities[i].quarter[red], i, initiative, blue);
				if (cities[i].quarter[red].HP <= 0) {
					Flag_Change(blue, cities[i]);
					cities[i].quarter[red].Init();
				}
				else Flag_Change(None, cities[i]);
			}
		}
	}
	for (int i = num_of_city; i; --i)// 处理红方司令部的奖励
		if (red_win[i] && cities[i].quarter[red].HP > 0) Reward(cities[i].quarter[red], red);
	for (int i = 1; i <= num_of_city; ++i) {
		if (cities[i].quarter[red].HP <= 0) cities[i].quarter[red].Init();
		if (cities[i].quarter[blue].HP <= 0) cities[i].quarter[blue].Init();
	}
}

inline void Report_for_Element()// 总部报告生命元
{
	printf("%03d:%02d %d elements in red headquarter\n", Globle_hour, Globle_minute, headquarters[red].element_num);
	printf("%03d:%02d %d elements in blue headquarter\n", Globle_hour, Globle_minute, headquarters[blue].element_num);
}

inline void Print_for_Arms(Soldier reporter, const int& camp)
{
	if (camp == red)
		printf("%03d:%02d red %s %d has ", Globle_hour, Globle_minute, name_table[reporter.soldier_type], reporter.id);
	else 
		printf("%03d:%02d blue %s %d has ", Globle_hour, Globle_minute, name_table[reporter.soldier_type], reporter.id);
	Weapon possession_arrow, possession_bomb, possession_sword;
	bool flag = 0;
	for (std::vector<Weapon>::iterator it = reporter.arms.begin(); it != reporter.arms.end(); ++it) {
		if ((*it).type == arrow) possession_arrow = (*it);
		if ((*it).type == bomb) possession_bomb = (*it);
		if ((*it).type == sword) possession_sword = (*it);
	}
	if (possession_arrow.type != None) { printf("arrow(%d)", possession_arrow.last); flag = 1; }
	if (possession_bomb.type != None) {
		if (possession_arrow.type != None) printf(",");
		printf("bomb");
		flag = 1; 
	}
	if (possession_sword.type != None) {
		if (possession_arrow.type != None || possession_bomb.type != None) printf(",");
		flag = 1;
		printf("sword(%d)", possession_sword.sharpness);
	}
	if (!flag) printf("no weapon");
	puts("");
}

inline void Report_for_Arms()// 武士报告武器
{
	// 自西向东报告, 红方司令部中的蓝方武士应该是蓝方之中最先报告的
	for (int i = 1; i <= num_of_city; ++i)
		if (cities[i].quarter[red].soldier_type != None)
			Print_for_Arms(cities[i].quarter[red], red);
	for (std::vector<Soldier>:: iterator it = headquarters[blue].enemies.begin(); it != headquarters[blue].enemies.end(); ++it)
			Print_for_Arms(*it, red);

	for (std::vector<Soldier>:: iterator it = headquarters[red].enemies.begin(); it != headquarters[red].enemies.end(); ++it)
			Print_for_Arms(*it, blue);
	for (int i = 1; i <= num_of_city; ++i)
		if (cities[i].quarter[blue].soldier_type != None)
			Print_for_Arms(cities[i].quarter[blue], blue);
}

inline void Read()
{
	scanf("%d%d%d%d%d", &first_element, &num_of_city, &atk_of_arrow, &dec_of_loyalty, &end_of_time);
	scanf("%d%d%d%d%d", &element_num_when_born[dragon], &element_num_when_born[ninja], &element_num_when_born[iceman], &element_num_when_born[lion], &element_num_when_born[wolf]);
	scanf("%d%d%d%d%d", &atk_when_born[dragon], &atk_when_born[ninja], &atk_when_born[iceman], &atk_when_born[lion], &atk_when_born[wolf]);

	for (int i = 0; i <= num_of_city + 1; ++i)
		cities[i].Init(i);
	headquarters[red].Init(red); headquarters[blue].Init(blue);
	Globle_hour = 0; Globle_minute = 0; Globle_clock = 0;
	winner = None;
	// 注意初始化
}

inline void Work()
{
	while (Globle_clock <= end_of_time) {
		if (Globle_minute >= minutes_per_hour) {
			Globle_minute %= minutes_per_hour;
			Globle_hour++;
		}// 过了一个小时
		switch (Globle_minute) {
			case time_of_born: {
				headquarters[red].Born();
				headquarters[blue].Born();
				break; 
			}
			case time_of_escape: { Escape(); break; }
			case time_of_march: {
				March();
				if (winner != None) return;
				break;
			}
			case time_of_produce: { Produce(); break; }
			case time_of_earn: { Earn(); break; }
			case time_of_shoot: { Shoot(); break; }
			case time_of_bomb: { Bomb(); break; }
			case time_of_fight: { Fight(); break; }
			case time_of_report_for_element: { Report_for_Element(); break; }
			case time_of_report_for_arms: { Report_for_Arms(); break; }
		}
		Globle_clock++;
		Globle_minute++;
	}
}

#define SUBMIT
int main(int argc, char const *argv[])
{
#ifdef SUBMIT
	freopen("wow.in", "r", stdin); freopen("wow.out", "w", stdout);
#endif	

	int t;
	scanf("%d", &t);
	for (int i = 1; i <= t; ++i) {
		printf("Case %d:\n", i);
		Read();
		Work();
	}

#ifndef SUBMIT
	printf("\n----------\n");
	getchar(); getchar();
#else
	fclose(stdin); fclose(stdout);
#endif		
		
	return 0;
}