2018ICPC网络赛南京站 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 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

思路:用map<int,int> 才存储牌的类型和张数就行,把,1,2,都加上13,就不需要特判了,因为map是有序的。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 14;
map<int,int> vz[205];
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif  
    int T,cas=1; scanf("%d",&T);
    while(T--){
        int N,M; scanf("%d %d",&N, &M);
        queue<int> Q;
        for(int i=1;i<=M;++i){
            int tmp;
            scanf("%d",&tmp);
            if(tmp<=2) tmp+=13; 
            Q.push(tmp);
        }
        for(int i=1;i<=N;++i){
            int cnt = 0;
            while(!Q.empty() && cnt<5){
                cnt++;
                int x = Q.front(); Q.pop();
                vz[i][x]++;
            }
        }
        int win;
        int last=-1,cur=0,pp=-1;
        bool epy = false;
        if(Q.empty()){
            epy = true;
        }
        while(1)
        {
            map<int,int> ::iterator it;
            bool ed=0;
            for(int i=1;i<=N;i++)
            {
                if(i==pp)//都不能出牌
                {
                    last=-1;
                    for(int j=0;j<N&&!Q.empty();j++)
                    {
                        int now=i+j;
                        if(now>N) now-=N;
                        int x=Q.front();Q.pop();
                        vz[now][x]++;
                        if(Q.empty()) epy=1;
                    }
                }
                if(last==15) continue;
                bool chu=0;
                for(it=vz[i].begin();it!=vz[i].end();it++)
                {
                    if(it->second==0) continue;
                    int tmp=it->first;
                    if(last==-1||tmp==15||tmp==last+1)//出牌成功
                    {
                        //last=tmp;
                        chu=1;
                        cur=tmp;
                        pp=i;
                        vz[i][tmp]--;
                        break;
                    }
                }
                if(chu==0) continue;
                last=cur;
                bool zero=1;
                for(it=vz[i].begin();it!=vz[i].end();it++)
                {
                    if(it->second==0) continue;
                    else
                    {
                        zero=0;
                        break;
                    }
                }
                if(zero)
                {
                    win=i;
                    ed=1;
                    break;
                }
            }
            if(ed) break;
        }
        printf("Case #%d:\n",cas++);
        for(int i=1;i<=N;i++)
        {
            if(i==win)
            {
                printf("Winner\n");
            }
            else
            {
                LL res=0;
                map<int,int>::iterator it;
                for(it=vz[i].begin();it!=vz[i].end();it++)
                {
                    int tmp=it->first;
                    if(tmp>13) tmp-=13;
                    res+=1LL*tmp*it->second;
                }
                printf("%lld\n",res);
            }
            vz[i].clear();
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40774175/article/details/82291319
今日推荐