ACM-ICPC 2018 南京赛区网络预赛 C. GDY

传送门:https://nanti.jisuanke.com/t/30992

Feeling bored, a group of hamsters decide to play a kind of card game named "GDY".

"GDY" is a kind of card game. To begin with, we pile up mm cards with a number from 1-131−13 written on into a stack. Then every player, numbered from 1-n1−n in clockwise order, takes turn to draw 55 cards from the top of the stack. Every player draws 55 cards in a single time, and then his next player draws cards.

After all the players finish drawing their cards, player 11 will play exactly one card. For simplicity, player 11 will only play the minimum card in his hand, the order of cards is defined as follows:

3<4<5<6<7<8<9<103<4<5<6<7<8<9<10
<11<12<13<1<2<11<12<13<1<2.

After player 11's turn, players from 2-n2−n take their turns in clockwise order, For each player, he should play the card which is exactly the next one of the card played by previous player according the order above. For example, if the previous player played card 44, the current player must play card 55, not card 6,76,7 or any other card (except card 22).

Card 22 can be played at anyone's turn as long as his previous player didn't play card 22. If a player has a card can be played in his hand, he will always play it in his turn. If he can play both 22 and the next card in his turn, he will choose to play the next card first.

If a player can't play any card, he has to pass his turn and do nothing. If all the players can't play any card and pass their turns after player XX's turn, all the players from player XX should draw one card from the card stack in clockwise order (include player XX). After that, player XX will play the minimum card in his hand, and the game goes on.

Once there is no card in the stack, skip all the chance for drawing cards, which means if a player need to draw card according the rules above, he will simply ignore this rule and do nothing. But it's guaranteed that every player will have at least one card in hand before player 11's first turn.

If one player has no card in his hand at anytime, he will become the winner, and the game ends. Other players should calculate their penalties. The penalty of a player is defined as the sum of numbers written on the cards in his hand.

Now you have known the information about a round of GDY, please find out the result of this round.

Input

There are multiple test cases in the input data.

The first line contains a integer TT: number of test cases. T \le 50T≤50.

For each test case, the first line contain 22 integers n, mn,m, representing the number of players, the number of cards in the original stack. 2\le n\le 200, m\le 200002≤n≤200,m≤20000.

The next line contains mm integers separated by a blank, representing the original stack. The leftmost one is the top of the stack and the rightmost is the bottom.

For all the test cases, it's guaranteed that the sum of mm doesn't exceed 4 \times 10^54×105.

Output

For each test case, print "Case #xx:"(without quotes) in the first line, where xx is the test case number.

Then, print nn lines representing the result of each player.

For the ii-th line, if player ii wins, print a string"Winner"(without quotes) at this line.

Otherwise, print a integer, the penalty of the ii-th player.

样例输入复制

2
2 10
3 5 7 9 11 4 6 8 10 12
3 15
4 5 6 7 8 9 10 11 12 13 2 2 2 2 2

样例输出复制

Case #1:
Winner
12
Case #2:
26
55
Winner

题意:n个人打牌,有m个牌,先每个人按顺序从牌库抽5张(如果牌库抽干了那有人可能不满五张)。牌大小顺序是3~13递增,1比3-13都大,2比1和3-13都大(相当于1是14,2 是15)。大家按1-n再1-n的顺序出牌,一直到决出胜者为止。胜者条件是牌库抽空且它自己手牌用完。每次每个人出牌都要出自己手里最小的牌,而且这张牌面值必须是上一次上个人出的牌+1(第一次第一人出牌直接出自己最小的牌),如果最小的牌不符合条件,如果有2那就出2,不然这个人只能空过。如果从i开始,其他人都空过了一轮,那么从i开始大家每个人按顺序从牌库抽一张牌(牌库干了就没得抽了假装抽空气吧)。最后输出每个人手里还剩的牌的面值和。

思路:快乐(?)模拟

吐槽:有个地方x=x-n写成了x=1,wa了10次吧怀疑人生了

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxv=222;

int t,n,m,q[maxv][20],num[maxv];

void init()
{
	memset(num,0,sizeof(num));
	memset(q,0,sizeof(q));
}

int main()
{
	int cas=0;
	scanf("%d",&t);
	while(t--)
	{
		queue<int>qq;
		init();
		scanf("%d%d",&n,&m);
		int tp;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&tp);
			tp=tp<=2?tp+13:tp;
			qq.push(tp);
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=5;j++)
			{
				if(!qq.empty())
				{
					int x=qq.front();
					qq.pop();
					q[i][x]++;
					num[i]++;
				}
			}
		}
		int pre=-1;
		int w=-1,now=1,em=0;
		while(w==-1)
		{
			if(pre==-1)
			{
				for(int i=3;i<=15;i++)
				{
					if(q[now][i])
					{
						q[now][i]--;
						num[now]--;
						pre=i;
						em=0;
						if(qq.empty()==true&&num[now]==0)
						{
							w=now;
							break;
						}
						break;
					}
				}
			}
			else if(q[now][pre+1])
			{
				q[now][pre+1]--;
				num[now]--;
				pre++;
				em=0;
				if(qq.empty()==true&&num[now]==0)
				{
					w=now;
					break;
				}
			}
			else if(q[now][15]&&pre!=15)
			{
				pre=15;
				q[now][15]--;
				num[now]--;
				em=0;
				if(qq.empty()==true&&num[now]==0)
				{
					w=now;
					break;
				}
			}
			else
			{
				em++;
			}
			if(em>=n-1)
			{
				if(!qq.empty())
				{
					for(int i=1;i<=n&&!qq.empty();i++)
					{
						int ccc=qq.front();
						qq.pop();
						int x=i+now;
						if(x>n)
							x=x-n;//写成x=1wa了那么10次吧
						q[x][ccc]++;
						num[x]++;
					}
				}
				em=0;
				pre=-1;
			}
			now++;
			if(now>n)
				now=1;
		}
		printf("Case #%d:\n",++cas);
		for(int i=1;i<=n;i++)
		{
			int sum=0;
			if(i==w)
			{
				printf("Winner\n");
			}
			else
			{
				for(int j=3;j<=15;j++)
				{
					int xx=j>13?j-13:j;
					sum=sum+q[i][j]*xx;
				}
				printf("%d\n",sum);
			}
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值