shunfurh
编程介的小学生
2017-08-25 17:12
采纳率: 92.7%
浏览 822
已采纳

Let's play UNO

Problem Description
Uno is a famous card game played with a specially printed deck. 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:

  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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐