ACM-ICPC 2018 南京赛区网络预赛 C. GDY [ 模拟 ]

2 篇文章 0 订阅

题目链接:

ACM-ICPC 2018 南京赛区网络预赛 C. GDY

题意概括:

有 n 个仓鼠玩牌。有 13 种牌面分别标着整数 1至13 。现在有 m 张牌叠在一起(会有重复的牌),规则如下:

先轮流摸牌一次,每次摸 5 张。牌的数量保证每只仓鼠都有至少一张牌。因此最后一只可能只能拿到少于 5 张的牌,但不会没牌

第 1 位首先出其牌面数字最小的牌,后一位出牌面刚好大 1 的牌。也就是说,当前只能出比前一张大一的牌或牌 2 。大小关系:

3<4<5<6<7<8<9<10<11<12<13<1<2

只要前一张牌不是 2 ,牌 2 在任何时候都可以出,不需要满足刚好比前一张牌大 1

若当前有牌可出,则一定要打出。若无牌可出则什么都不用做。

若第 X 位出了牌后,其他几位的都无牌可出,经过一轮又回到 X 时:

从 X 开始轮流抽一张牌,若到某位没有牌了,则跳过不抽。抽完后,从 X 开始,出其牌面最小的牌,以此循环\cdots \cdots

数据范围:

T\leq50

2\leq n\leq200,m\leq20000

题解分析:

就是纯模拟题,看懂题面就完成了一大半。为了方便操作,这里维护一个二维数组

int player[MAXN][14] 

player[i][j] 表示的是第 i 位拥有牌面为 j 的牌的数目

一定要仔细啊,有很多细节会出错。比赛的时候没找出错在哪里,赛后队友帮我debug出来的

AC代码:

#include <stdio.h>
#include <memory.h>
using namespace std;
typedef long long ll;
const int MAXN = 210;
int player[MAXN][15], n, m;
int card[20005], start;

int Next[14] = {0, 2, -1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};

int Min(int *p) {
    for (int i = 3; i <= 13; i++)
        if(p[i]) return i;
    if(p[1]) return 1;
    if(p[2]) return 2;
    return 0;
}

bool judge(int *p) {
    for (int i = 1; i <= 13; i++)
        if (p[i]) return false;
    return true;
}

void print(int id) {
    printf("Case #%d:\n", id);
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        for (int j = 1; j <= 13; j++) {
            sum += j * player[i][j];
        }
        if (sum) printf("%d\n", sum);
        else printf("Winner\n");
    }
}

int main () {
    int T;
    scanf("%d", &T);
    for (int k = 1; k <= T; k++)
    {
        memset(player, 0, sizeof(player));
        memset(card, 0, sizeof(card));
        start=0;
        
        scanf("%d%d", &n, &m);
        for (int i = 0; i < m; i++) {
            scanf("%d", &card[i]);
        }
        
        for (int i = 1; i <= n && start < m; i++)
            for (int j = 0; j < 5 && start < m; j++){
                player[i][card[start++]] ++;
            }
        
        int p = 2, cur = Min(player[1]), next, last = 1;
        player[1][cur] --;
        while (1) {
            if (last != p) {
                next = Next[cur];
                if (next != -1 && player[p][next]) {
                    player[p][next] --;
                    cur = next;
                    last = p;
                    if (judge(player[p]))
                        break;
                }
                else if (player[p][2] && cur != 2) {
                    player[p][2] --;
                    cur = 2;
                    last = p;
                    if (judge(player[p]))
                        break;
                }
                p = p % n + 1;
            }
            else {
                if(start < m)
                {
                    int temp = card[start++];
                    player[last][temp] ++;
                    if(start < m)
                    {
                        int t = last % n + 1;
                        while(t != last && start != m)
                        {
                            int temp = card[start++];
                            player[t][temp] ++;
                            t = t % n + 1;
                        }
                    }
                }
                cur = Min(player[last]);
                player[last][cur] --;
                if (judge(player[last])) break;
                p = p % n + 1;
            }
        }
        print(k);
    }
}

 

                                                                  GDY

                                                                                     65536K    2000ms

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−13 written on into a stack. Then every player, numbered from 1−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−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 2).

Card 2 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 X should draw one card from the card stack in clockwise order (include player X). 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 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 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×10^{5}.

Output

For each test case, print "Case #xx:"(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.

样例输入

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

题目来源

ACM-ICPC 2018 南京赛区网络预赛

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值