UVa127 "Accordian" Patience (模拟)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
以上是关于UVa127 "Accordian" Patience (模拟)的主要内容,如果未能解决你的问题,请参考以下文章
UVa127 "Accordian" Patience (模拟)
"Accordian" Patience (UVa 127) 双向链表 栈
UVA 12563 "Jin Ge Jin Qu hao" (背包)