1003. Hit or Miss
来源:互联网 发布:淘宝店铺售假扣26分 编辑:程序博客网 时间:2024/05/16 18:43
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.
24 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 134 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 13Case 2: unwinnable
#include <iostream>#include <queue>using namespace std;int main(){int t;cin>>t;for(int z=1;z<=t;z++){int num;cin>>num;queue<short> deck[11];short result[11],temp;for(int i=0;i<52;i++) //初始化{cin>>temp;deck[0].push(temp);}bool win=false;short totalsteps[11]={0}; //记录总数以便判断是否出现死循环(lose)short count[11]={0}; //记录人数的数short j=0; //遍历每个人short totalcard=52; //判断牌是否全部丢弃,为0则是while(!win){if(deck[j].empty()){j++;if(j>=num) j=0;continue;}totalsteps[j]++;count[j]++;if(count[j]==deck[j].front()){deck[j+1].push(deck[j].front());totalsteps[j]=0;if(j+1==num) totalcard--; //j+1==num时牌被放在假想人手上,总牌数减一result[j]=deck[j].front();deck[j].pop();}else {deck[j].push(deck[j].front());deck[j].pop();}if(totalsteps[j]>(int)deck[j].size()*13){win=false; break;}if(totalcard==0) win=true;if(count[j]==13) count[j]=0;j++;if(j>=num) j=0;}if(win){cout<<"Case "<<z<<":";for(int i=0;i<num;i++)cout<<" "<<result[i];cout<<endl;}else cout<<"Case "<<z<<": unwinnable"<<endl;}return 0;}
- 1003. Hit or Miss
- 1003. Hit or Miss
- Sicily 1003. Hit or Miss
- sicily--1003. Hit or Miss
- siciy 1003. Hit or Miss
- sicily 1003. Hit or Miss
- Sicily 1003. Hit or Miss
- sicily 1003. Hit or Miss
- Sicily 1003. Hit or Miss
- [sicily] 1003. hit or miss
- sicily 1003. Hit or Miss
- Sicily 1003. Hit or Miss
- [sicily online]1003. Hit or Miss
- 1003: Hit or Miss
- 1003 Hit or Miss
- soj1003. Hit or Miss
- sicily 1003 Hit or Miss
- soj.1003 hit or miss
- Microsoft IIS FTP Service Remote Buffer Overflow Vulnerability
- 自连接、外连接和自连接查询
- 在Ubuntu下,建立下载image文件到Mini2440或者TQ2440开发板的环境
- Cypher查询语言--Neo4j中的SQL(2)
- Linux下的CPU利用率计算原理详解
- 1003. Hit or Miss
- java中为什么在static中不能使用this关键字
- Document.Cookie 取得的Cookies不完整問題
- 煩躁,結束,開始
- 文档视图结构下多视图间的控制
- Android开发之道(9)RadioBox、CheckBox和Spinner
- 代码实现ImageView的Padding
- How to rebuild Intel Raid (isw) on Linux
- WCF初入(1) 开篇之一