Description

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
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
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
#include <iostream>
#include <vector>
#include <queue> using namespace std; int main(int argc, char const *argv[])
{
int testCase;
cin >> testCase;
int personNum, cardValue;
int t = ;
int personCountValue[];
int lastCard[];
while (t <= testCase) {
vector<queue<int> > personCard;
cin >> personNum;
personCard.resize(personNum); for (int i = ; i != personNum; ++i) // 初始化
personCountValue[i] = ;
for (int i = ; i != ; ++i) { // 输入牌的顺序
cin >> cardValue;
personCard[].push(cardValue);
} int repeatNum = ;
int succeedNum = ;
bool isSucceed = false;
// 最大循环次数,其实就是考虑一个极限,如果一个人当前拥有全部的卡,然后跑了 52 遍,把全部卡都遍历了也没用给一张给后面的,那么就是循环了
int maxRepeatNum = * ;
while (repeatNum <= maxRepeatNum) {
repeatNum++;
for (int i = ; i != personNum; ++i) {
if (personCard[i].empty()) { // 计算成功的人的个数,全部成功则跳出,因为后面的人的牌不能给前面的人,所以前面的人为空了name它以后都为空
succeedNum++;
if (succeedNum == personNum) {
isSucceed = true;
break;
}
continue;
} else {
succeedNum = ;
} int frontN = personCard[i].front();
personCard[i].pop();
if (frontN == personCountValue[i]) { // 当前计数和最上方的卡号相同
lastCard[i] = frontN;
repeatNum = ;
if (i < personNum - ) {
personCard[i + ].push(frontN);
}
} else {
personCard[i].push(frontN);
}
personCountValue[i]++;
if (personCountValue[i] == )
personCountValue[i] = ;
}
if (isSucceed) {
break;
}
}
cout << "Case " << t++ << ": ";
if (isSucceed) {
for (int i = ; i < personNum - ; ++i)
cout << lastCard[i] << " ";
cout << lastCard[personNum - ] << endl;
} else {
cout << "unwinnable" << endl;
}
}
return ;
}

sicily 1003. Hit or Miss的更多相关文章

  1. sicily 1003. hash

    Description 请用HASH链式法来解决冲突,且规定链表在链表头插入新元素. 规定HASH函数为:h(x) = x % 11,即哈希数组下标为0-10. 给定两种操作: I 操作,插入一个新的 ...

  2. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  3. Buffer cache hit ratio性能计数器真的可以作为内存瓶颈的判断指标吗?

    Buffer cache hit ratio官方是这么解释的:“指示在缓冲区高速缓存中找到而不需要从磁盘中读取的页的百分比.” Buffer cache hit ratio被很多人当做判断内存的性能指 ...

  4. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  5. Bestcoder#5 1003

    Bestcoder#5 1003 Poor RukawTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. LeetCode Design Hit Counter

    原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...

  8. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  9. dp 动态规划 hdu 1003 1087

    动态规划就是寻找最优解的过程 最重要的是找到关系式 hdu 1003 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意:求最大字序列和, ...

随机推荐

  1. Apache Hadoop YARN – ResourceManager--转载

    原文地址:http://zh.hortonworks.com/blog/apache-hadoop-yarn-resourcemanager/ ResourceManager (RM) is the ...

  2. C++解析(8):C++中的新成员

    0.目录 1.动态内存分配 1.1 C++中的动态内存分配 1.2 new关键字与malloc函数的区别 1.3 new关键字的初始化 2.命名空间 2.1 作用域与命名空间 2.2 命名空间的定义和 ...

  3. Count the string HDU - 3336

    题意: 求一个字符串的每个前缀在这个字符串中出现次数的加和 解析: 默默的骂一句...傻xkmp..博主心里气愤... 拓展kmp就好多了... 因为拓展kmp每匹配一次   就相当于这些前缀出现了一 ...

  4. VLC for Android 编译过程

    首先,给一个VLC的官网链接:VLC-AndroidCompile 上面有编译所需要安装的插件,环境变量的配置等等信息:虽然是英语,但也挺好理解,这里就不再详述:此文主要记录我在编译的过程中遇到的一些 ...

  5. 【BZOJ2329】括号修复(Splay)

    [BZOJ2329]括号修复(Splay) 题面 BZOJ 洛谷 题解 本来想着用线段树来写 但是有一个区间翻转 所以不能用线段树了,就只能用平衡树 然后直接\(Splay\)就好了 注意一下几个标记 ...

  6. 使用Hexo搭建GitHub博客(2018年Mac版)

    关于本文 本文仅记录自己学习搭建Hexo博客之时,搭建过程中掉坑的历程总结,对零基础起步的观众朋友可能缺乏某些基础技术的指导,请优先食用下述两篇优质教程: [2018更新]小白独立搭建博客-Githu ...

  7. Linux之GDB调试介绍与应用20170601

    一.GDB调试命令   描述 backtrace(或bt) 查看各级函数调用及参数 finish 连续运行到当前函数返回为止,然后停下来等待命令 frame(或f) 帧编号 选择栈帧 info(或i) ...

  8. Java国密相关算法(bouncycastle)

    公用类算法: PCIKeyPair.java /** * @Author: dzy * @Date: 2018/9/27 14:18 * @Describe: 公私钥对 */ @Data @AllAr ...

  9. php使用时间戳保存时间的意义

    时间戳记录的是格林尼治时间,使用date格式化的时候会根据你程序设置的不同时区显示不同的时间. 如果使用具体时间,则还需要进行多一步转换.

  10. windows环境libevent搭建和demo分析

    libevent框架之前有做过分析,这次是谈谈如何将libevent搭建在vs工作环境下, 并且编写一个demo进行测试.测试过程中会再一次带大家分析消息是怎么传递 的. 我的libevent版本li ...