RE
查看原帖
RE
706798
gzxworld楼主2024/7/18 17:46
#include <bits/stdc++.h>


using namespace std;

int n, m, k;

int p = 0;

int f = 1;

int flag = -1;

map < string, int > mp;

string tower[500000];

int tower_top = 1;

struct player
{
	string name;
	
	string cards[10];
	
	int cnt = 3;
	
	bool dob = 0;
}a[1000];

map < char, int > mp2;

map < char, int > mp3;

bool cmp2(string x, string y)
{
	return mp2[x[0]] < mp2[y[0]];
}

bool cmp3(string x, string y)
{
	return mp3[x[0]] < mp3[y[0]];
}

int res(string x)
{
	if(x[0] == 'A')
	{
		return p + mp[x];
	}
	else if(x[0] == 'B')
	{
		return p - mp[x];
	}
	else if(x[0] == 'C')
	{
		return p * mp[x];
	}
	else if(x[0] == 'D')
	{
		return (int)floor(p / (1.0 * mp[x]));
	}
	else if(x[0] == 'E')
	{
		return mp[x];
	}
}

int nexxt(int num)
{
	int ans = num + 1 * f;
	if(ans > n)
	{
		ans = 1;
	}
	else if(ans < 1)
	{
		ans = n;
	}
	return ans;
}

int intt = 1;

void lost(int num)
{
	for (int i = 1 ; i <= 3 ; i ++)
	{
		a[num].cards[i] = tower[tower_top ++];
	}
	for (int i = 1 ; i <= n ; i ++)
	{
		a[i].dob = 0;
	}
}

void work(int num);

void test(int num)
{
//	cout << a[num].name << ": ";
//	for (int i = 1 ; i <= 3 ; i ++)
//	{
//		cout << a[num].cards[i] << ' ';
//	}
//	cout << '\n';
}

void work_notdob(int num)
{
	int newp = -INT_MAX + 1;
	
	sort(a[num].cards + 1, a[num].cards + 1 + a[num].cnt, cmp2);
	
	test(num);
	
	int pos = -1;
	for (int i = 1 ; i <= a[num].cnt ; i ++)
	{
		if(a[num].cards[i].size() <= 3)
		{
			if(res(a[num].cards[i]) <= 99)
			{
				if(res(a[num].cards[i]) > newp)
				{
					newp = res(a[num].cards[i]);
					pos = i;
				}
			}
		}
	}
	
	if(pos == -1)
	{
		for (int i = 1 ; i <= a[num].cnt ; i ++)
		{	
			if(a[num].cards[i].size() > 3)
			{
				a[num].dob = 0;
				if(a[num].cards[i] == "PASS")
				{
					cout << a[num].name << " used " << "PASS" << ",now p=" << p << ".\n";
					a[num].cards[i] = tower[tower_top ++];
					work(nexxt(num));
					return ;
				}
				else if(a[num].cards[i] == "TURN")
				{
					cout << a[num].name << " used " << "TURN" << ",now p=" << p << ".\n";
					a[num].cards[i] = tower[tower_top ++];
					f = -f;
					work(nexxt(num));
					return ;
				}
				else if(a[num].cards[i] == "double")
				{
					cout << a[num].name << " used " << "DOUBLE" << ",now p=" << p << ".\n";
					a[num].cards[i] = tower[tower_top ++];
					a[nexxt(num)].dob = 1;
					work(nexxt(num));
					return ;
				}
			}
		}
		cout << a[num].name << " lost the game.\n";
		intt = num;
		flag = 1;
		lost(num);
		return ;
	}
	else
	{
		p = newp;
		cout << a[num].name << " used " << a[num].cards[pos] << ",now p=" << p << ".\n";
		a[num].cards[pos] = tower[tower_top];
		tower_top ++;
		work(nexxt(num));
		return ;
	}
}

void work_dob(int num)
{
	int newp = 1000;
	
	sort(a[num].cards + 1, a[num].cards + 1 + a[num].cnt, cmp3);
	
	test(num);
	
	for (int i = 1 ; i <= a[num].cnt ; i ++)
	{
		if(a[num].cards[i].size() > 3)
		{
			a[num].dob = 0;
			if(a[num].cards[i] == "PASS")
			{
				cout << a[num].name << " used " << a[num].cards[i] << ",now p=" << p << ".\n";
				a[num].cards[i] = tower[tower_top ++];
				work(nexxt(num));
				return ;
			}
			else if(a[num].cards[i] == "TURN")
			{
				cout << a[num].name << " used " << a[num].cards[i] << ",now p=" << p << ".\n";
				a[num].cards[i] = tower[tower_top ++];
				f = -f;
				work(nexxt(num));
				return ;
			}
			else if(a[num].cards[i] == "double")
			{
				cout << a[num].name << " used " << "DOUBLE" << ",now p=" << p << ".\n";
				a[num].cards[i] = tower[tower_top ++];
				a[nexxt(num)].dob = 1;
				work(nexxt(num));
				return ;
			}
		}
	}
	
	int pos = -1;
	for (int i = 1 ; i <= a[num].cnt ; i ++)
	{
		if(a[num].cards[i].size() <= 3)
		{
			if(res(a[num].cards[i]) <= 99)
			{
				if(res(a[num].cards[i]) < newp)
				{
					newp = res(a[num].cards[i]);
					pos = i;
				}
			}
		}
	}
	
	if(pos == -1)
	{
		cout << a[num].name << " lost the game.\n";
		intt = num;
		flag = 1;
		lost(num);
		return ;
	}
	else
	{
		p = newp;
		cout << a[num].name << " used " << a[num].cards[pos] << ",now p=" << p << ".\n";
		a[num].cards[pos] = tower[tower_top];
		tower_top ++;
		a[num].dob = 0;
		work(num);
		return ;
	}
}

void work(int num)
{
	if(a[num].dob == 0)
	{
		work_notdob(num);
	}
	else
	{
		work_dob(num);
	}
}
signed main()
{
//	freopen("P7506_10.in", "r", stdin);
//	freopen("awa.out", "w", stdout);
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> k;
	
	mp2['C'] = 1, mp2['A'] = 2, mp2['B'] = 3, mp2['D'] = 4, mp2['E'] = 5, mp2['P'] = 6, mp2['T'] = 7, mp2['d'] = 8;
	mp3['D'] = 1, mp3['B'] = 2, mp3['A'] = 3, mp3['C'] = 4, mp3['E'] = 5, mp3['d'] = 0, mp3['T'] = -1, mp3['P'] = -2;
	
	mp["A1"] = 1, mp["A2"] = 2, mp["A5"] = 5, mp["A9"] = 9, mp["A19"] = 19, mp["A49"] = 49, mp["A99"] = 99;
	mp["B1"] = 1, mp["B9"] = 9, mp["B19"] = 19, mp["C2"] = 2, mp["D2"] = 2, mp["E0"] = 0, mp["E49"] = 49, mp["E99"] = 99;
	for (int i = 1 ; i <= n ; i ++)
	{
		cin >> a[i].name;
		cin >> a[i].cards[1] >> a[i].cards[2] >> a[i].cards[3];
		for (int j = 1 ; j <= 3 ; j ++)
		{
			if(a[i].cards[j] == "DOUBLE")
			{
				a[i].cards[j] = "double";
			}
		}
	}
	for (int i = 1 ; i <= k ; i ++)
	{
		string x;
		cin >> x;
		if(x == "DOUBLE")
		{
			x = "double";
		}
		tower[tower_top ++] = x;
	}
	tower_top = 1;
	for (int i = 1 ; i <= m ; i ++)
	{
		p = 0;
		f = 1;
		cout << "Round " << i << ":\n";
		work(intt);
	}
	return 0;	
}


2024/7/18 17:46
加载中...