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

Input

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.

Output

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 <bits/stdc++.h>
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
*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM-ICPC(国际大学生程序设计竞)是一项面向大学生的计算机编程竞,涉及算法和数据结构等领域。在比中,选手需要解决一系列编程问题,使用合适的算法和数据结构来实现正确和高效的解决方案。 对于整理ACM-ICPC模板,以下是一些建议: 1. 了解比要求:首先,你需要了解ACM-ICPC的具体要求和规则。这包括了解比所涉及的算法和数据结构,以及题目的类型和难度等。 2. 收集资料:收集与ACM-ICPC相关的资料,包括经典算法和数据结构的实现代码、常见问题的解题思路等。可以参考教材、博客、论文等资源。 3. 整理模板:将收集到的资料整理成模板。可以按照算法和数据结构的分类进行整理,例如排序算法、图算法、字符串算法等。对每个模板,添加必要的注释和示例代码,以便理解和使用。 4. 测试代码:对每个模板编写测试代码,确保它们的正确性和可靠性。可以使用已知的测试用例或自行设计测试用例。 5. 更新与扩充:定期更新和扩充模板,以适应ACM-ICPC中新出现的算法和数据结构。同时,根据自己的经验和理解,对模板进行优化和改进。 6. 练习和复习:在比之前,利用整理好的模板进行练习和复习。尝试解决一些经典问题,使用模板中的算法和数据结构进行实现,并进行优化。 希望这些建议对你整理ACM-ICPC模板有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值