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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/OscaronMar/article/details/82290389

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;
                } 
            } 
    } 
} 

猜你喜欢

转载自blog.csdn.net/OscaronMar/article/details/82290389
今日推荐