2 shunfurh shunfurh 于 2017.09.06 21:15 提问

Hit or Miss

One very simple type of solitaire game known as ��Hit or Miss�� (also known as ��Frustration,�� ��Harvest,�� ��Roll-Call,�� ��Talkative��, and ��Treize��) is played as follows: take a standard deck of 52 playing cards - four sets of cards numbered 1 through 13 (suits do not matter in this game) which have been shuffled - and start counting through the deck 1, 2, 3, . . . , and so on. When your count reaches 13, start over at 1. Each time you count, look at the top card of the deck and do one of two things: if the number you count matches the value of the top card, discard it from the deck; if it does not match it, move that card to the bottom of the deck. You win the game if you are able to remove all cards from the deck (which may take a very long time).

A version of this game can be devised for two or more players. The first player starts as before with a 52 card deck, while the other players have no cards initially. As the first player removes cards from her deck, she gives them to the second player, who then starts playing the same game, starting at count 1. When that player gets a match, he passes his card to the third player, and so on. The last player discards matches rather than passing them to player 1. All players who have cards to play with perform the following 2-step cycle of moves in lockstep:

  1. Each player says his or her current count value and checks for a match. If there is no match, the top card is moved to the bottom of the deck; otherwise it is passed to the next player (or discarded if this is the last player).

  2. Each player except the first takes a passed card (if there is one) and places it at the bottom of his or her deck.

These rules are repeated over and over until either the game is won (all the cards are discarded by the last player) or an unwinnable position is reached. If any player ever runs out of cards, he waits until he is passed a card and resumes his count from where he left off. (e.g., if player 3 passes his last card on a count of 7, he waits until he receives a card from player 2 and resumes his count with 8 at the beginning of the next 2-step cycle).

Input

Input will consist of multiple input sets. The first line of the file will contain a single positive integer nindicating the number of input sets in the file. Each input set will be a single line containing 53 integers: the first integer will indicate the number of players in the game and the remaining 52 values will be the initial layout of the cards in the deck, topmost card first. These values will all lie in the range 1 . . . 13, and the number of players will lie in the range 1. . . 10.

Output

For each input set, output the input set number (as shown below, starting with 1) and either the phrase ��unwinnable�� or a list showing the last card discarded by each player. Use a single blank to separate all outputs.

Sample Input

NOTE: Each sample input set below is split across multiple lines in order to fit on the page �C in the actual file each set will be on a single line.

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

Case 1: 13 13 13 13
Case 2: unwinnable

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.22 08:16
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
CACHE的Miss和Hit
1.L1 CACHE的Miss和Hit 1.1 Read Miss 见2.1。 1.2 Write Miss L1D是Read-allocate CACHE,意味着仅在发生Read Miss时才会读入新的行。如果写Miss发生,数据通过一个Write Buffer写到低一级内存,从而把L1D CACHE旁路。写buffer包含4个entries,每个entry是64位宽。 1.3 Wri
cache 读写 miss与hit
什么叫cache  读 miss  什么叫cache 读hit 什么叫cache  写 miss  什么叫cache 写hit? cache 读 miss与hit  很好理解 但是 cache 写 为什么也会miss与hit呢?cache 还会写失败么?为什么写数据也会失败?不命中? 怎么判断cpu想要读或者写的东西是否在cache中。
hit or miss 解题报告
hit or miss 解题报告 方法一:#include<iostream> using namespace std; const int maxn=10010; const int maxm=15; int i,j,k,m,n; int sum; int head[maxm],tail[maxm],counter[maxm]; int f[maxm][maxn];int check(int c
sicily 1003. Hit or Miss
代码中有注释,应该看得懂 判断游戏不会结束时,大概设置了参数为13   if (giveCount[i] > 13*q[i].size() )   没偿试13换成其他参数行不行,反正2是不行的 #include #include #include #include using namespace std; int main() { int testCase;
Sicily 1003. Hit or Miss
模拟题,上网看中文才弄懂题意,不难,记住要设最长循环时间,过了就算输。 #include #include using namespace std; int main(int argc, char const *argv[]) { int t,n,temp,cnt = 1; cin >> t; while(t--) { cin >> n; queuecar
1003. Hit or Miss
#include #include #include //#include using namespace std; int players; queue pl[11]; int matchingNum[10]; int ct; void play() { while(pl[players].size() != 52 && ct != 52 * 13) { /*system("
1003: Hit or Miss
  Q1003: Hit or Miss—问题描述一个非常简单的纸牌游戏叫做“Hit or Miss”(也叫做“Frustration”,“Harvest”,“Roll-Call”,“Talkative”或“Treize”),它的玩法如下:准备一副已经洗乱的52张的扑克牌——4个由1至13的集合(花色对此游戏没有影响),然后开始数1,2,3,……,等,当你数到13时,又从1开始数。每数
sicily 1003 Hit or Miss
这道题做起来比较像在做阅读理解......表示英语不好的伤不起。 读了M次,没怎么懂题意,最后在参考其他人的代码才明白过来。 这里有一个讲解题意讲的比较清楚的,我就不累赘了。 http://blog.csdn.net/chenhq1991/article/details/7795757 #include #include #include using namespace std;
siciy 1003. Hit or Miss
#include #include #include #include using namespace std; int main(int argc, char *argv[]) { int t; scanf("%d",&t); for( int k = 1; k<=t ; k++) { int current_count[10]; int last_remove[10]; i
soj1003. Hit or Miss
 1003. Hit or Miss Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One very simple type of solitaire game known as "Hit or Miss" (also known as "Frustration," "Harvest,"