sicily 1003. 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 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.
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.
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
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的更多相关文章
- sicily 1003. hash
Description 请用HASH链式法来解决冲突,且规定链表在链表头插入新元素. 规定HASH函数为:h(x) = x % 11,即哈希数组下标为0-10. 给定两种操作: I 操作,插入一个新的 ...
- [LeetCode] Design Hit Counter 设计点击计数器
Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...
- Buffer cache hit ratio性能计数器真的可以作为内存瓶颈的判断指标吗?
Buffer cache hit ratio官方是这么解释的:“指示在缓冲区高速缓存中找到而不需要从磁盘中读取的页的百分比.” Buffer cache hit ratio被很多人当做判断内存的性能指 ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- Bestcoder#5 1003
Bestcoder#5 1003 Poor RukawTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 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 ...
- LeetCode Design Hit Counter
原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- dp 动态规划 hdu 1003 1087
动态规划就是寻找最优解的过程 最重要的是找到关系式 hdu 1003 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意:求最大字序列和, ...
随机推荐
- BZOJ4915 简单的数字题
不妨设a1<a2<a3<a4.显然第一问的答案是4,满足a1+a4=a2+a3,a1+a2|a3+a4,a1+a3|a2+a4.容易发现将其同时扩大k倍是仍然满足条件的,于是考虑gc ...
- [区分] 1.计算机网络/internet(互联网) 2.Internet(因特网) 3.www/web(万维网)
internet(互联网或互连网)是一个通用名词,泛指由多个计算机网络互联而成的虚拟网络.Inernet(因特网)是一个专用名词,指当前全球最大的.开放的.由众多网络相互连接而成的特定的计算机网络,它 ...
- JAVA里面"=="和euqals的区别
(1)基本数据类型,用双等号“==”比较,比较的是他们的值,值类型是存储在内存中的栈中 (2)复合数据类型中, 当他们用“==”进行比较的时候,比较的是他们在内存中的存放地址,其变量在栈中仅仅是存储引 ...
- MySQL5.7初始配置
MySQL5.7初始配置 Windows7 环境安装MySQL5.7配置命令 <<<<<<<<<<<<<<<& ...
- Intel WIDI (Wireless Display) 相关技术知识分析
一. WIFI 1.如何查找WIFI设备 非p2p设备 Beacons 包(同步,SSID) 速率 1M/s 2.4G HZ 13个信道,1,6,11三个信道不重叠 2.P2P 认证 客户端在每个通道 ...
- Bootstrap 环境安装
下载 Bootstrap 可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本.当点击这个链接时,将看到如下所示的网页: 您会看到两个按钮: Downloa ...
- 【Python简介】
一.Python的简介 1.什么是python? Python(发音:[ 'paiθ(ə)n; (US) 'paiθɔn ]),是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的通用 ...
- Codeforces 576D. Flights for Regular Customers(倍增floyd+bitset)
这破题调了我一天...错了一大堆细节T T 首先显然可以将边权先排序,然后逐个加进图中. 加进图后,倍增跑跑看能不能到达n,不能的话加新的边继续跑. 倍增的时候要预处理出h[i]表示转移矩阵的2^0~ ...
- centos上部署nginx服务
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- 根据数据库连接的java.sql.Connection获取数据库名称
// 获取数据库的元数据信息 DatabaseMetaData metaData = conn.getMetaData(); // 获取数据库名称的方法 System.out.println(meta ...