Sicily 1905. Let’s play UNO

1905. Let’s play UNO

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Uno is a famous card game played with a specially printed deck (Figure 5.7.1). It’s very popular as a funny game in a party. A so-called “official rules” is presented at the Wikipedia, but there are a lot of different extended rules all over the world according to their specific needs. In this problem, you are required to obey our rules introduced below:
The Uno deck consists of cards of 4 colors: red(R), green(G), blue(B), and yellow(Y). Each color has two kinds of cards, number cards and action cards. The ranks in number cards are 0-9. There are 3 "action" cards in each color, labeled "skip"(S), "draw two"(D), and "reverse"(R). The functions of the actions will be described afterwards. For each color, there are two copies of each positive number card and action card, but only one zero card, producing 25 cards in total.
Besides, there are also special black action cards called “wild cards”, "wild"(WC) and "wild draw four"(WF). There are four "wild" and "wild draw four" cards each. Hence, there are 108 cards in total.
In this problem, a card is marked with an ID of two characters length, the first is the color (R, G, B, Y, W) while the second is the rank (0-9, S, D, R, C, F). For example, the ID of red 2 is R2, the yellow reverse is YR, the wild cards are WC and WF.
Supposed there are n players numbered from 1 to n clockwise. Before playing, players take turns(in the order of 1, 2, ... n) to pick seven successive cards from the stock. The top card of the remaining stock is exposed to start the game, treated as if player 1 dropped that card. The exposed card will never be WC or WF in this problem. Then the game begins clockwise (next player is 2), or counter-clockwise (next player is n) if the top exposed card is a reverse. 
At each turn, a player may drop a card from their hand that matches the color or rank of the top exposed card (e.g., if the top card is R3, you can drop R5 or G3; if the top card is RD, you can drop R3 or GD) or play a WC. What’s more, if the player has a WF and no other legal cards to drop, he can drop the WF. Then the card dropped just now becomes the top exposed card.
If a player has no legal cards, he must draw the top card of the stock and place it in his hand. After dropping a single card or drawing, the next player clockwise takes a turn, or counter-clockwise when the reverse is in effect.
When a player drops down to only one card, that player is required to say "uno" to warn other players. The game ends when a player drops all his/her cards, or the stock is emptied but the current player has to draw a card. If the last card is an action card, the special effect still occurs.
When the game ends, all players count the number of points pertaining to the values of the cards in their hands. Number cards worth the face value on them, colored special cards worth twenty, and wilds worth fifty, e.g., R2 worth 2, G0 worth 0, BD and YS worth 20, WC and WF worth 50.
The descriptions of the action cards (Figure 5.7.2):
 
Now here comes the problem. There are N people playing Uno under the rules mentioned above. Given the sequence of the 108 cards of the stock, you are asked to simulate a Uno game. 
At each turn, the player will always drop a card if permitted. If there are more than one choices, the player will drop the card with the largest point. If still a tie, he will choose the one whose ID is the smallest alphabetical order.
When a player drops WC or WF, he has to name a color. The first time he will name red, the second time he will name green, the third time blue, the fourth time yellow, the fifth time red again, and so on.
When the game ends, you should output the final score of each player, and we also want to know how many times each player calls “Uno”.

 

Input

The first line of the input file contains a single number: the number of test cases to follow. Each test case has two lines:
The first line contains the number of players N , with 2<=N<=10.
The second line contains 108 IDs of the Uno cards, separated by one space. Each ID is two characters long as introduced in the description above. 

Output

For each test case, output two lines:
The first line are N integers, the ith integer is the final score of player i.
The second lines are also N integers, the ith integer shows how many times player i calls “Uno”. 

Sample Input

1
2
R9 RD RD RS RS RR RR B0 B1 B1 B2 B2 B3 B3 G0 GD GD GS GS GR GR G9 G9 G8 G8 G7 G7 G6 G6 G5 G5 G4 G4 G3 G3 G2 G2 G1 G1 Y0 Y9 Y9 Y8 Y8 Y7 Y7 Y6 Y6 Y5 Y5 Y4 Y4 Y3 Y3 Y2 Y2 Y1 Y1 YD YD YS YS YR YR R9 R8 R8 R7 R7 R6 R6 R5 R5 R4 R4 R3 R3 R2 R2 R1 R1 R0 B4 B4 B5 B5 B6 B6 B7 B7 B8 B8 B9 B9 BD BD BS BS BR BR WC WC WC WC WF WF WF WF

Sample Output

249 0
0 1

Hint

The process of this game is:

G0(exposed) 
-> B0(Player 2)		-> Draw GD(Player 1)		-> B3(Player 2) 
->Draw GD(Player 1)	-> B3(Player 2) 			-> Draw GS(Player 1)
-> B2(Player 2)		-> Draw GS(Player 1)		-> B2(Player 2)
-> Draw GR(Player 1)	-> B1, call “Uno”(Player 2)	-> Draw GR(Player 1) 
-> B1(Player 2), end.

Score of player 1: 20*12(6 red action cards and 6 green action cards)+9(R9)

// Problem#: 1905
// Submission#: 3590699
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <string.h>
#include <ctype.h>

const int MAXC = 108;
const int MAXP = 10;
const char color_chr[] = "RGBY";

char stock[MAXC][3];
int sp;
char hand[MAXP][MAXC][3];
int count[MAXP];
int uno[MAXP];
int color[MAXP];
char cur[3];
int pl;
int dir;
int fst;
int n;

int draw(int p, int t) {
    while (t--) {
        if (sp >= MAXC) return 0;
        strcpy(hand[p][count[p]], stock[sp]);
        count[p]++;
        sp++;
    }
    return 1;
}

int value(char c[]) {
    if (c[0] == 'W') return 50;
    if (!isdigit(c[1])) return 20;
    return c[1] - '0';
}

int one_turn() {
    int i, j, k;
    if (fst) {
        j = count[pl];
        draw(pl, 1);
        fst = 0;
    } else {
        for (j = k = -1, i = 0; i < count[pl]; i++) {
            char * card = hand[pl][i];
            if (card[1] == 'F') {
                k = i;
            } else {
                if (card[0] != cur[0] && card[1] != cur[1]) {
                    if (card[0] != 'W') continue;
                } 
                if (j < 0) {
                    j = i;
                } else {
                    int vj = value(hand[pl][j]);
                    int vi = value(card);
                    if (vj < vi || vj == vi && strcmp(hand[pl][j], card) > 0)
                        j = i;
                }
            }
        }
    }
    if (j < 0) j = k;
    if (j < 0) {
        if (!draw(pl, 1)) return 0;
    } else {
        strcpy(cur, hand[pl][j]);
        strcpy(hand[pl][j], hand[pl][count[pl] - 1]);
        count[pl]--;
        int p = pl;
        if (count[pl] == 1) uno[pl]++;
        if (cur[0] == 'W') {
            int & c = color[pl];
            cur[0] = color_chr[c];
            c = (c + 1) % 4;
        }
        if (cur[1] == 'R') dir = n - dir;
        else if (cur[1] == 'S') pl = (pl + dir) % n;
        else if (cur[1] == 'D') {
            pl = (pl + dir) % n;
            if (!draw(pl, 2)) return 0;
        } else if (cur[1] == 'F') {
            pl = (pl + dir) % n;
            if (!draw(pl, 4)) return 0;
        }
        if (count[p] == 0) return 0;
    }
    pl = (pl + dir) % n;
    return 1;
}

int main() {
    int cs;
    scanf("%d", &cs);
    while (cs--) {
        scanf("%d", &n);
        for (int i = 0; i < MAXC; i++) scanf("%s", stock[i]);
        sp = 0;
        for (int i = 0; i < n; i++) {
            count[i] = uno[i] = color[i] = 0;
            draw(i, 7);
        }
        fst = 1;
        pl = 0;
        dir = 1;
        while (one_turn());
        for (int i = 0; i < n; i++) {
            int s = 0;
            for (int j = 0; j < count[i]; j++) 
                s += value(hand[i][j]);
            printf("%d%c", s, i + 1 < n ? ' ' : '\n');
        }
        for (int i = 0; i < n; i++)
            printf("%d%c", uno[i], i + 1 < n ? ' ' : '\n');
    }
    return 0;
}                                 


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值