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

  1. 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
  2. 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
  3. 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
  4. 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
  5. #

Sample Output

  1. 6 piles remaining: 40 8 1 1 1 1
  2. 1 pile remaining: 52
  3.  
  4. 麻烦的模拟。手写栈,每个pile都是个栈,用pos数组来记录位置和pile编号的关系。
  1. #include<cstdio>
  2.  
  3. struct card
  4. {
  5. char R, s;//Rank,suit
  6. card(){}
  7. card(char R, char s):R(R),s(s){}
  8. bool operator == (const card& rhs) const {// match
  9. return R == rhs.R || s == rhs.s;
  10. }
  11. };
  12.  
  13. struct Stack
  14. {
  15. card ele[];
  16. int Top;
  17.  
  18. card* top(){ return ele+Top;}
  19. void pop(){Top--;}
  20. void push(const card& x){
  21. ele[++Top] = x;
  22. }
  23. }pile[];
  24.  
  25. int pileSz;
  26.  
  27. int pos[];//pos 2 pile
  28.  
  29. void Move(int p, int d)
  30. {
  31. int id = pos[p], pid = pos[p-d];
  32.  
  33. pile[pid].push(*pile[id].top());
  34. pile[id].pop();
  35.  
  36. if(pile[id].Top == ){
  37. pileSz--;
  38. for(int i = p; i < pileSz; i++)
  39. pos[i] = pos[i+];
  40. }
  41. }
  42.  
  43. bool check()
  44. {
  45. int move3 = -;
  46. for(int i = ;i < pileSz; i++) {
  47. if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move3 = i; break; }
  48. }
  49. int move1 = -;
  50. for(int i = ;i < pileSz; i++) {
  51. if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move1 = i; break; }
  52. }
  53.  
  54. if(!~move1 && !~move3) return false;
  55.  
  56. if(~move1&&~move3){
  57. if(move1 < move3) Move(move1,);
  58. else Move(move3,);
  59. }
  60. else {
  61. if(~move1) Move(move1,);
  62. else Move(move3,);
  63. }
  64.  
  65. return true;
  66. }
  67.  
  68. bool read(){
  69. char buf[];
  70. scanf("%s",buf);
  71. if(*buf == '#') return false;
  72. for(int i = ; i < ; i++) pos[i] = i;
  73. pileSz = ;
  74. for(int i = ; i < ; i++) pile[i].Top = ;
  75.  
  76. pile[].push(card(*buf,buf[]));
  77.  
  78. for(int i = ; i < ; i++) {
  79. scanf("%s",buf);
  80. pile[i].push(card(*buf,buf[]));
  81. }
  82.  
  83. return true;
  84. }
  85.  
  86. int main()
  87. {
  88. // freopen("in.txt","r",stdin);
  89. while(read()){
  90. while(check());
  91. /* poj
  92. printf("%d piles remaining:",pileSz);
  93. for(int i = 0; i < pileSz; i++)
  94. printf(" %d",pile[pos[i]].Top);
  95. */
  96. if(pileSz>){
  97. printf("%d piles remaining:",pileSz);
  98. for(int i = ; i < pileSz; i++)
  99. printf(" %d",pile[pos[i]].Top);
  100. }
  101. else printf("1 pile remaining: 52");
  102.  
  103. puts("");
  104. }
  105. return ;
  106. }
  1.  

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. 面试问题 - C# 接口和抽象类的区别

    这个问题基本上可以说是 面试时的必问问题 C# 中的接口和抽象类 相同点: 1. 都不能直接实例化,都可以通过继承实现其抽象方法 2. 都是面向抽象编程的技术基础,实现了诸多的设计模式 不同点: 1. ...

  2. 使用LinearLayout实现ListView,解决ListView和ScrollView滚动冲突

    在项目中,我们常常会遇到一个ScrollView里面会嵌套ListView的情况,但往往你会发现,ListView和ScrollView的滚动时间会有冲突问题,造成ListView不能完全显示.虽然网 ...

  3. ASP.NET学习笔记(三)ASP Global.asa 文件

    Global.asa 文件 Global.asa 文件是一个可选的文件,它可包含可被 ASP 应用程序中每个页面访问的对象.变量以及方法的声明.所有合法的浏览器脚本都能在 Global.asa 中使用 ...

  4. LeetCode: 598 Range Addition II(easy)

    题目: Given an m * n matrix M initialized with all 0's and several update operations. Operations are r ...

  5. spring-eureka 源码解读----为什么一个服务最多两分钟被其他服务感知

    Eureka的wiki上有一句话,大意是一个服务启动后最长可能需要2分钟时间才能被其它服务感知到,但是文档并没有解释为什么会有这2分钟.其实这是由三处缓存 + 一处延迟造成的. 首先,Eureka对H ...

  6. maven 参考

    系列文章,通俗易懂,可以看看 http://www.cnblogs.com/AlanLee/category/918828.html

  7. XML与JSON的区别

    JSON和XML的比较 ◆可读性 JSON和XML的可读性可谓不相上下,一边是简易的语法,一边是规范的标签形式,很难分出胜负. ◆可扩展性 XML天生有很好的扩展性,JSON当然也有,没有什么是XML ...

  8. Memcache未授权访问漏洞利用及修复

    Memcached是一套分布式的高速缓存系统.它以Key-Value(键值对)形式将数据存储在内存中,这些数据通常是应用读取频繁的.正因为内存中数据的读取远远大于硬盘,因此可以用来加速应用的访问.本文 ...

  9. 【手撸一个ORM】第八步、查询工具类

    一.实体查询 using MyOrm.Commons; using MyOrm.DbParameters; using MyOrm.Expressions; using MyOrm.Mappers; ...

  10. Maven--setting详解

    settings.xml有什么用? 如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径. settings.xml文件是干什么的,为什么要配置它呢? ...