UVa127 "Accordian" Patience (模拟)

链接:http://acm.hust.edu.cn/vjudge/problem/18732分析:模拟,用了vector调用erase时可以自动调整大小的特性,居然没T。
 1 #include <cstdio>
 2 #include <string>
 3 #include <vector>
 4 #include <stack>
 5 #include <iostream>
 6 using namespace std;
 7
 8 int main() {
 9     string s;
10     while (cin >> s && s != "#") {
11         vector<stack<string> > piles(52);
12         piles[0].push(s);
13         for (int i = 1; i < 52; i++) {
14             cin >> s;
15             piles[i].push(s);
16         }
17         while (true) {
18             bool isMove = false;
19             for (int i = 0; i < piles.size(); i++) {
20                 string& card = piles[i].top();
21                 if (i - 3 >= 0) {
22                     string& card1 = piles[i - 3].top();
23                     if (card[0] == card1[0] || card[1] == card1[1]) {
24                         piles[i - 3].push(card);
25                         if (piles[i].size() == 1) piles.erase(piles.begin() + i);
26                         else piles[i].pop();
27                         isMove = true;
28                         break;
29                     }
30                 }
31                 if (i - 1 >= 0) {
32                     string& card1 = piles[i - 1].top();
33                     if (card[0] == card1[0] || card[1] == card1[1]) {
34                         piles[i - 1].push(card);
35                         if (piles[i].size() == 1) piles.erase(piles.begin() + i);
36                         else piles[i].pop();
37                         isMove = true;
38                         break;
39                     }
40                 }
41             }
42             if (!isMove) break;
43         }
44         cout << piles.size() << " pile" << (piles.size() > 1 ? "s" : "") << " remaining: ";
45         for (int i = 0; i < piles.size(); i++) {
46             if (i) cout << ‘ ‘;
47             cout << piles[i].size();
48         }
49         cout << ‘\n‘;
50     }
51     return 0;
52 }
 
时间: 2024-11-08 07:02:38

UVa127 "Accordian" Patience (模拟)的相关文章

UVa127,&quot;Accordian&quot; Patience

注意1堆的时候,pile后面没有s!!!!因为这个WA了一次,否则就1A了 犯了一个很幼稚很幼稚的错误,申请ans[]后玩了吧ans置0,结果调了好长好长时间,本来是敲完就能过的T T啊啊啊啊啊啊,一个多小时没了啊 附上我调试时写的代码(把每一次运转都输出了= =一个一个看的,真心用了好长时间,头都大了) #include <iostream> #include <cstdio> #include <string> #include <cstring> #i

ACM学习历程——UVA127 &quot;Accordian&quot; Patience(栈, 链表)

Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate n

ACM学习历程——UVA 127 &quot;Accordian&quot; Patience(栈;模拟)

Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate n

UVa OJ 127 - &quot;Accordian&quot; Patience (“手风琴”纸牌)

UVa OJ 127 - "Accordian" Patience ("手风琴"纸牌) Time limit: 3.000 seconds 限时:3.000秒 Problem 问题 You are to simulate the playing of games of "Accordian" patience, the rules for which are as follows: 模拟玩一个"手风琴"纸牌游戏,规则如下: D

Uva 127 poj 1214 `Accordian&#39;&#39; Patience

 ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on

&quot;Accordian&quot; Patience UVA 127 (”手风琴“牌游戏)

"Accordian" Patience From:UVA, 127 Submit Time Limit: 3000 MS You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever th

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

UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比较简单,这里纯粹使用指针做了,非常麻烦的指针操作,一不小心就错.调试起来还是非常费力的 本题理解起来也是挺费力的,要搞清楚如何模拟也不容易啊,读题要很仔细. 纯指针的操作挺快的吧.不过POJ 0ms,而UVa就0.2左右了. 三相链表: 1 只要有叠起来的牌,那么就使用一个down指针指向下面的牌就可以了. 2 使用双向链表,可以方便前后遍历. 3 记得有了更新牌之后,又要重新开始检查是否需要更新牌,这是

uva ``Accordian&#39;&#39; Patience

题目如下: ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour

``Accordian&#39;&#39; Patience UVA 127

说说: 这道题难度其实并不但,但是比较繁琐,且细节容易被忽略.先分析一下游戏规则吧,知道游戏规则之后,问题自然而然就解决了.首先放着一行52个扑克牌堆(ps:输入的时候分两行输入)开始每堆只有一张牌,然后从左到右开始判断,若一张牌和左边第一张牌或者左边第三张牌的大小或者花色相同,则将该张牌放到那一对牌之上并且要求继续向左匹配,直到不能匹配为止.若某个堆一张牌都不剩了,则该堆不存在了,也就是说如果两堆相邻,则两堆的牌数都不能为0.最后按照这个规则,直到没有牌能够移动位置.(ps:移动是指顶层牌的移