记录编号 346124 评测结果 AAAAAAAAAA
题目名称 杀手游戏 最终得分 100
用户昵称 Gravatar小e 是否通过 通过
代码语言 C++ 运行时间 0.028 s
提交时间 2016-11-11 21:28:22 内存使用 0.25 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

const int Ghost = 1, Grenade = 2, Knife = 3, Bang = 4;
const int Miss = 5, Parry = 6;
const int Iamcs = 0, Peipei = 1;

int cardcnt;
int v[1100];
map <string, int> Match;// 牌与数字的对应
struct Player
{
	int HP;
	int cards[10];// 每种牌的数量
	inline Player() { HP = 4; memset(cards, 0, sizeof cards); }
	inline void Clear() { HP = 4; memset(cards, 0, sizeof cards); }
	inline void Push(const int& a) { cards[a]++; }
}p[2];
// 假设Iamcs先手

inline void Init()
{
	Match["Ghost"] = 1;
	Match["Grenade"] = 2;
	Match["Knife"] = 3;
	Match["Bang"] = 4;
	Match["Miss"] = 5;
	Match["Parry"] = 6;
}

inline void Clear()
{
	cardcnt = 0;
	memset(v, 0, sizeof v);
	p[Iamcs].Clear();
	p[Peipei].Clear();
}

inline bool Read()
{
	int cnt = 0;
	Clear();
	string tmp;
	while (1) {
		cin >> tmp; 
		// cout << tmp << endl;
		if (tmp == ".") return 0;
		if (tmp == "===") return 1;
		v[++cnt] = Match[tmp];
	}
}

inline void Get_Cards(const int& id, const int& num)
{
	for (int i = 1; i <= num; ++i)
		p[id].Push(v[++cardcnt]);
}

inline int Death()
{
	if (p[Peipei].HP <= 0)  return Peipei;
	else if (p[Iamcs].HP <= 0) return Iamcs;
	return 2;
}

inline void Deal_With_Ghost(const int& num)// 响应Ghost
{
	if (p[num].cards[Bang] > 0) p[num].cards[Bang]--;
	else p[num].HP--;
}
inline void Throw_Ghost(const int& num)// num的人打出Ghost(如果有这张牌)
{
	while (p[num].cards[Ghost] > 0) {
		p[num].cards[Ghost]--;
		Deal_With_Ghost(num ^ 1);
	}
}

inline void Deal_With_Grenade(const int& num)
{
	if (p[num].cards[Parry] > 0) {
		p[num].cards[Parry]--;
		Get_Cards(num, 1);
	}
	else if (p[num].cards[Miss] > 0) p[num].cards[Miss]--;
	else p[num].HP--;
}
inline void Throw_Grenade(const int& num)
{
	while (p[num].cards[Grenade] > 0) {
		p[num].cards[Grenade]--;
		Deal_With_Grenade(num ^ 1);
	}
}

inline void Deal_With_Bang(const int& num)
{
	if (p[num].cards[Parry] > 0) {
		p[num].cards[Parry]--;
		Get_Cards(num, 1);
	}
	else if (p[num].cards[Miss] > 0) p[num].cards[Miss]--;
	else p[num].HP--;
}
inline void Throw_Bang(const int& num)// Bang只能用一次
{
	if (p[num].cards[Bang] > 0) {
		p[num].cards[Bang]--;
		Deal_With_Bang(num ^ 1);
	}
}

inline void Throw_Knife(const int& num)
{
	while (p[num].cards[Knife] > 0) {
		p[num].cards[Knife]--;
		p[num ^ 1].HP--;
	}
}

inline void Throw_Away(const int& num, const int& type)// 弃牌
{
	while (1) {
		int sum = 0;
		for (int i = 1; i <= 6; ++i)
			sum += p[num].cards[i];
		if (sum <= p[num].HP) break;
		if (p[num].cards[type] > 0) p[num].cards[type]--;
		else break;
	}
}

inline void Work()
{
	Get_Cards(Iamcs, 4); Get_Cards(Peipei, 4);// 初始手牌
// DEBUG2:
// 		Debug();
	while (1) {
		Get_Cards(Iamcs, 2);
		Throw_Ghost(Iamcs);
		Throw_Grenade(Iamcs);
		Throw_Bang(Iamcs);
		Throw_Knife(Iamcs);
		Throw_Away(Iamcs, Bang);
		Throw_Away(Iamcs, Miss);
		Throw_Away(Iamcs, Parry);
		if (Death() == Peipei) { printf("WIN\n"); return; }

		Get_Cards(Peipei, 2);
		Throw_Ghost(Peipei);
		Throw_Grenade(Peipei);
		Throw_Bang(Peipei);
		Throw_Knife(Peipei);
		Throw_Away(Peipei, Bang);
		Throw_Away(Peipei, Miss);
		Throw_Away(Peipei, Parry);
		if (Death() == Iamcs) { printf("LOSE\n"); return; }
// DEBUG1:
// 		Debug();		
	}
}

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

	Init();
	while (Read())
		Work();

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

	return 0;
}