(南京区域资格赛)C-GDY

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 m cards with a number from 1-13 written on into a stack. Then every player, numbered from 1-n in clockwise order, takes turn to draw 5 cards from the top of the stack. Every player draws 5 cards in a single time, and then his next player draws cards.

After all the players finish drawing their cards, player 1 will play exactly one card. For simplicity, player 1 will only play the minimum card in his hand, the order of cards is defined as follows: 3<4<5<6<7<8<9<10<11<12<13<1<2.
After player 1’s turn, players from 2-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 4, the current player must play card 5, not card 6,7 or any other card (except card 2).

Card 2 can be played at anyone’s turn as long as his previous player didn’t play card 2. 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 2 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 X’s turn, all the players from player X should draw one card from the card stack in clockwise order (include player X). After that, player X 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 1’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 T: number of test cases.
T <= 50
For each test case, the first line contain 2 integers n, m, representing the number of players,the number of cards in the original stack. 2≤n≤200, m≤20000.
The next line contains m 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 m doesn’t exceed 4 X 10^5

Output
For each test case, print “Case #x:”(without quotes) in the first line, where x is the test case number. Then, print n lines representing the result of each player. For the i-th line, if player i wins, print a string” Winner” (without quotes) at this line. Otherwise, print a integer, the penalty of the i-th player.

Sample Input
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
Sample Output
Case #1:
Winner
12
Case #2:
26
55
Winner
题目链接:https://nanti.jisuanke.com/t/30992

#include<stdio.h>
#include<queue>
#include<iostream>
#include<string.h>
using namespace std;
    int main() { 
        int t;
        scanf("%d",&t); 
        for(int p=1;p<=t;p++){ 
            int n;
            scanf("%d",&n); 
            int m;
            scanf("%d",&m); 
            int arr[205][205]; 
            memset(arr,0,sizeof(arr)); 
            queue<int> q; 
            int temp;
            for(int i=0;i<m;i++){
                scanf("%d",&temp); 
                q.push(temp%13); 
            } 
            for(int i=0;i<5*n;i++){ 
                if(q.empty())
                    break; 
                arr[i/5][q.front()]++; 
                q.pop(); 
            } 
            int nowcard=0,nowplayer=0; 
            for(int i=3;i<=15;i++){ 
                if(arr[0][i%13] != 0){ 
                    nowcard=i%13; 
                    arr[0][i%13]--; 
                    break; 
                } 
            } 
            int lastplayer=0; 
            while(true){ 
                nowplayer=(nowplayer+1)%n; 
                if(lastplayer==nowplayer){ 
                    for(int i=0;i<n;i++){ 
                        if(q.empty()) 
                            break; 
                        arr[(nowplayer+i)%n][q.front()]++; 
                        q.pop();
                    } 
                    for(int i=3;i<=15;i++){ 
                        if(arr[nowplayer][i%13]!=0){ 
                            nowcard=i%13; 
                            arr[nowplayer][i%13]--; 
                            break; 
                        } 
                    } 
                } else if(nowcard!=2){ 
                    if(arr[nowplayer][(nowcard+1)%13]!=0){ 
                        arr[nowplayer][(nowcard+1)%13]--;               
                        lastplayer=nowplayer; 
                        nowcard=(nowcard+1)%13; 
                    } else if(arr[nowplayer][2]!=0){ 
                        arr[nowplayer][2]--; 
                        lastplayer=nowplayer; 
                        nowcard=2; 
                    } 
                } 
                int sum=0; 
                for(int i=0;i<13;i++){
                    sum+=arr[nowplayer][i]; 
                } 
                if(sum==0) 
                    break; 
            } 
            cout<<"Case #"<<p<<":"<<endl; 
            for(int i=0;i<n;i++){ 
                int sum=arr[i][0]*13; 
                for(int j=1;j<13;j++){ 
                    sum+=arr[i][j]*j; 
                } 
                if(sum == 0){
                    cout<<"Winner"<<endl;
                } else{
                    cout<<sum<<endl;
                } 
            } 
    } 
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值