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 mmm cards with a number from 1−131-131−13 written on into a stack. Then every player, numbered from 1−n1-n1−n in clockwise order, takes turn to draw 555 cards from the top of the stack. Every player draws 555 cards in a single time, and then his next player draws cards.
After all the players finish drawing their cards, player 111 will play exactly one card. For simplicity, player 111 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<103<4<5<6<7<8<9<10
<11<12<13<1<2<11<12<13<1<2<11<12<13<1<2.
After player 111's turn, players from 2−n2-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 444, the current player must play card 555, not card 6,76,76,7 or any other card (except card 222).
Card 222 can be played at anyone's turn as long as his previous player didn't play card 222. 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 222 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 XXX's turn, all the players from player XXX should draw one card from the card stack in clockwise order (include player XXX). After that, player XXX 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 111'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.
There are multiple test cases in the input data.
The first line contains a integer TTT: number of test cases. T≤50T \le 50T≤50.
For each test case, the first line contain 222 integers n,mn, mn,m, representing the number of players, the number of cards in the original stack. 2≤n≤200,m≤200002\le n\le 200, m\le 200002≤n≤200,m≤20000.
The next line contains mmm 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 mmm doesn't exceed 4×1054 \times 10^54×105.
For each test case, print "Case #xxx:"(without quotes) in the first line, where xxx is the test case number.
Then, print nnn lines representing the result of each player.
For the iii-th line, if player iii wins, print a string"Winner"
(without quotes) at this line.
Otherwise, print a integer, the penalty of the iii-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
模拟题,比赛的时候没有看,并不难
#include
using namespace std;
int pile[20005],per[205][20],num[205];
int top,m,winner;
void get(int id)
{
if(top == m) return;
top++;
per[id][pile[top]]++;
num[id]++;
}
void put(int id,int pi)
{
per[id][pi]--;
num[id]--;
if(num[id] == 0) winner = id;
}
int main(void)
{
int T,n,kase;
scanf("%d",&T);
kase = 0;
while(T--) {
kase++;
bool flag = false;
memset(per,0,sizeof(per));
memset(num,0,sizeof(num));
scanf("%d %d",&n,&m);
top = 0;
for(int i = 1; i <= m; i++)
scanf("%d",&pile[i]);
for(int i = 1; i <= n; i++) {
for(int j = 0; j < 5; j++) {
get(i);
}
}
winner = 0;
int putid = 1,nextid = 1,pi;
bool f1;
while(!winner) {
if(nextid == putid) {
if(flag) {
for(int i = putid; i <= n; i++) get(i);
for(int i = 1; i < putid; i++) get(i);
}
flag = true;
f1 = false;
for(int i = 3; i <= 13; i++) {
if(per[putid][i]) {
pi = i;
put(putid,pi);
f1 = true;
break;
}
}
if(!f1) {
for(int i = 1; i <= 2; i++) {
if(per[putid][i]) {
pi = i;
put(putid,pi);
break;
}
}
}
if(putid == n) nextid = 1;
else nextid = putid + 1;
}
else {
if(pi == 13) {
if(per[nextid][1]) {
pi = 1;
put(nextid,1);
putid = nextid;
}
else if(per[nextid][2]) {
pi = 2;
put(nextid,2);
putid = nextid;
}
}
else if(pi != 2) {
if(per[nextid][pi + 1]) {
pi++;
putid = nextid;
put(nextid,pi);
}
else if(per[nextid][2]) {
pi = 2;
putid = nextid;
put(nextid,2);
}
}
nextid = (nextid == n ? 1 : nextid + 1);
}
}
printf("Case #%d:\n",kase);
int sum = 0;
for(int i = 1; i <= n; i++) {
sum = 0;
for(int j = 1; j <= 13; j++) {
sum += j * per[i][j];
}
if(sum) printf("%d\n",sum);
else printf("Winner\n");
}
}
return 0;
}
/*
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
*/