Input

Input data to the program specifies the order in which cards are dealt from the pack. The input contains pairs of lines, each line containing 26 cards separated by single space characters. The final line of the input file contains a # as its first character. Cards are represented as a two character code. The first character is the face-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second character is the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades).

Output

One line of output must be produced for each pair of lines (that between them describe a pack of 52 cards) in the input. Each line of output shows the number of cards in each of the piles remaining after playing ``Accordian patience'' with the pack of cards as described by the corresponding pairs of input lines.

Sample Input

QD AD 8H 5S 3H 5H TC 4D JH KS 6H 8S JS AC AS 8D 2H QS TS 3S AH 4H TH TD 3C 6S
8C 7D 4C 4S 7S 9H 7C 5D 2S KD 2D QH JD 6D 9D JC 2C KH 3D QC 6C 9S KC 7H 9C 5C
AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D TD 9D JD QD KD
AH 2H 3H 4H 5H 6H 7H 8H 9H KH 6S QH TH AS 2S 3S 4S 5S JH 7S 8S 9S TS JS QS KS
#

Sample Output

6 piles remaining: 40 8 1 1 1 1
1 pile remaining: 52 麻烦的模拟。手写栈,每个pile都是个栈,用pos数组来记录位置和pile编号的关系。
#include<cstdio>

struct card
{
char R, s;//Rank,suit
card(){}
card(char R, char s):R(R),s(s){}
bool operator == (const card& rhs) const {// match
return R == rhs.R || s == rhs.s;
}
}; struct Stack
{
card ele[];
int Top; card* top(){ return ele+Top;}
void pop(){Top--;}
void push(const card& x){
ele[++Top] = x;
}
}pile[]; int pileSz; int pos[];//pos 2 pile void Move(int p, int d)
{
int id = pos[p], pid = pos[p-d]; pile[pid].push(*pile[id].top());
pile[id].pop(); if(pile[id].Top == ){
pileSz--;
for(int i = p; i < pileSz; i++)
pos[i] = pos[i+];
}
} bool check()
{
int move3 = -;
for(int i = ;i < pileSz; i++) {
if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move3 = i; break; }
}
int move1 = -;
for(int i = ;i < pileSz; i++) {
if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move1 = i; break; }
} if(!~move1 && !~move3) return false; if(~move1&&~move3){
if(move1 < move3) Move(move1,);
else Move(move3,);
}
else {
if(~move1) Move(move1,);
else Move(move3,);
} return true;
} bool read(){
char buf[];
scanf("%s",buf);
if(*buf == '#') return false;
for(int i = ; i < ; i++) pos[i] = i;
pileSz = ;
for(int i = ; i < ; i++) pile[i].Top = ; pile[].push(card(*buf,buf[])); for(int i = ; i < ; i++) {
scanf("%s",buf);
pile[i].push(card(*buf,buf[]));
} return true;
} int main()
{
// freopen("in.txt","r",stdin);
while(read()){
while(check());
/* poj
printf("%d piles remaining:",pileSz);
for(int i = 0; i < pileSz; i++)
printf(" %d",pile[pos[i]].Top);
*/
if(pileSz>){
printf("%d piles remaining:",pileSz);
for(int i = ; i < pileSz; i++)
printf(" %d",pile[pos[i]].Top);
}
else printf("1 pile remaining: 52"); puts("");
}
return ;
}
 

Uva 127 poj 1214 `Accordian'' Patience 纸牌游戏 模拟的更多相关文章

  1. ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

  2. UVa 127 - &quot;Accordian&quot; Patience POJ 1214 链表题解

    UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...

  3. [刷题]算法竞赛入门经典(第2版) 6-9/UVa127 - "Accordian" Patience

    题意:52张牌排一行,一旦出现任何一张牌与它左边的第一张或第三张"匹配",即花色或点数相同,则须立即将其移动到那张牌上面,将其覆盖.能执行以上移动的只有压在最上面的牌.直到最后没有 ...

  4. HDU 2209 翻纸牌游戏 状态BFS

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem De ...

  5. hdu2209翻纸牌游戏

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  6. 翻纸牌游戏(dfs回溯)

    翻纸牌游戏 Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  7. HDU 2209 翻纸牌游戏(DFS)

    题目链接 Problem Description 有一种纸牌游戏,很有意思,给你N张纸牌,一字排开,纸牌有正反两面,开始的纸牌可能是一种乱的状态(有些朝正,有些朝反),现在你需要整理这些纸牌.但是麻烦 ...

  8. HDU 2209 翻纸牌游戏

    翻纸牌游戏 Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  9. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

随机推荐

  1. UVaLive 4727 Jump (递推)

    题意:约瑟夫环,求最后三个数. 析:f[i] = (f[i-1] + k) % i 这是求最后一个数时候,我们倒着推到第一个数时,只有一个数,所以当只有两个数时,就是另一数, 同理,我们可以求得第三个 ...

  2. ECMA 上传文件到SHarePoint 文档库

    <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/ ...

  3. junit 直接执行测试方法报错

    在eclipse中,直接右击test1->Run As->Junit Test,报下面的错: java.lang.NoSuchMethodError: org.junit.runner.R ...

  4. android实现简单计算器

    前台代码如下 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  5. h5模型文件转换成pb模型文件

      本文主要记录Keras训练得到的.h5模型文件转换成TensorFlow的.pb文件 #*-coding:utf-8-* """ 将keras的.h5的模型文件,转换 ...

  6. MySQL生成UUID

    UUID函数 在MySQL中,可以用uuid()函数来生成一个UUID,如下图: replace函数 默认生成的uuid含有'-',我们可以使用replace函数替换掉'-',SQL如下: selec ...

  7. 如何杀死defunct进程

    原文: How to kill defunct process 译者: youngsterxyf defunct进程是指出错损坏的进程,父子进程之间不会再通信.有时,它们会演变成“僵尸进程”,存留在你 ...

  8. shell编程 条件判断式----利用 case ..... esac 判断

    条件判断式----利用 case ..... esac 判断 case  $变量名称 in   <==关键词为 case ,还有变量前有钱字号 "第一个变量内容")   &l ...

  9. STP-9-处理RSTP中的拓扑变化

    STP能识别四种不同的拓扑变化事件, 而RSTP只有当非边界端口从非转发状态变为转发状态才认为发生了拓扑变化事件 因为刚变为转发状态的端口可以为一些mac地址提供比之前更好的路径,CAM表需要更新.失 ...

  10. css绘制各种形状

    代码:http://runjs.cn/code/9lyjtbxl: 效果:http://sandbox.runjs.cn/show/9lyjtbxl <!DOCTYPE html> < ...