【习题 6-9 UVA - 127】"Accordian" Patience
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
链表模拟即可。
1pile不能加s...
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
string s[N];
int l[N], r[N];
vector <string> v[N];
int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0), cin.tie(0);
while (cin >> s[1] && s[1] != "#") {
for (int i = 2; i <= 52; i++) cin >> s[i];
for (int i = 1; i <= 52; i++) v[i].clear();
for (int i = 1; i <= 52; i++) v[i].push_back(s[i]);
for (int i = 0; i <= 52; i++) l[i] = i - 1, r[i] = i + 1;
bool ok = true;
while (ok) {
ok = false;
for (int i = r[0]; i != 53; i = r[i]) {
int x1 = -1, x2 = -1, x3 = l[i];
if (x3 >= 0) x2 = l[x3];
if (x2 >= 0) x1 = l[x2];
if (x1 >= 1 && x1 <= 52 && (v[x1].back()[0] == v[i].back()[0] || v[x1].back()[1] == v[i].back()[1])) {
v[x1].push_back(v[i].back());
v[i].pop_back();
ok = true;
}else
if (x3 >= 1 && x3 <= 52 && (v[x3].back()[0] == v[i].back()[0] || v[x3].back()[1] == v[i].back()[1])) {
v[x3].push_back(v[i].back());
v[i].pop_back();
ok = true;
}
if (v[i].empty()) {
int ll = l[i], rr = r[i];
r[ll] = rr;
l[rr] = ll;
}
if (ok) break;
}
}
vector <int> ans;
ans.clear();
for (int i = r[0]; i != 53; i = r[i]) {
ans.push_back(v[i].size());
}
cout << (int)ans.size() << " pile";
if ((int)ans.size()!=1) cout <<"s";
cout<<" remaining:";
for (int i = 0; i <(int)ans.size(); i++)
cout << ' ' << ans[i];
cout << endl;
}
return 0;
}
【习题 6-9 UVA - 127】"Accordian" Patience的更多相关文章
- ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- UVa 127 - "Accordian" Patience
题目:52张扑克,从左到右在平面上排列,按着如下规则处理: 1.按照从左到右的顺序,如果一张牌和左边的第一张或者第三张匹配,就把它放到对应的牌上面. 2.如果可以移动到多个位置,移动到最左端的牌上面. ...
- Uva 127 poj 1214 `Accordian'' Patience 纸牌游戏 模拟
Input Input data to the program specifies the order in which cards are dealt from the pack. The inpu ...
- [刷题]算法竞赛入门经典(第2版) 6-9/UVa127 - "Accordian" Patience
题意:52张牌排一行,一旦出现任何一张牌与它左边的第一张或第三张"匹配",即花色或点数相同,则须立即将其移动到那张牌上面,将其覆盖.能执行以上移动的只有压在最上面的牌.直到最后没有 ...
- ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- UVa 127 - "Accordian" Patience POJ 1214 链表题解
UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...
- UVa 1637 - Double Patience(概率DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 170 - Clock Patience
题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上, 从中间组最上面一张牌開始.翻过来设为当前值,然后取当前值相应组中最上面的背过去的牌翻过 ...
- UVA 1637 Double Patience
题意:36张扑克,平分成9摞,两张数字一样的可以拿走,每次随机拿两张,问能拿光的概率. 解法:记忆化搜索,状态压缩.一开始我想在还没拿的时候概率是1,然后往全拿光推···样例过不去···后来觉得推反了 ...
随机推荐
- Linux 终端仿真程序Putty
PuTTY是一个Telnet.SSH.rlogin.纯TCP以及串行接口连接软件.较早的版本仅支持Windows平台,现在的版本中开始支持各类Unix平台. 用linux作为桌面系统,身为工程师很多时 ...
- 添加 validate 验证规则
上篇文章链接:http://blog.csdn.net/chenmoimg_/article/details/71191476 修改 msg.js $.extend($.validator.messa ...
- 客户端本地存储(cookie、web Storage、vuex)选择
一.cookie .localStorage .sessionStorage .vuex 比较 cookie 4K 有时效性 可服务器传递 cookie是由服务器产生,存储在客户端的一 ...
- libc.so.6: version GLIBC_2.14 not found
https://blog.csdn.net/heylun/article/details/78833050
- TCP简单说(下)
本文在Creative Commons许可证下发布 TCP的RTT算法 从前面的TCP重传机制我们知道Timeout的设置对于重传非常重要. 设长了,重发就慢,丢了老半天才重发,没有效率,性能差: 设 ...
- modSecurity规则学习(一)——配置文件
环境:modSecurity3.0,nignx1.13.8 modSecurity配置文件 1.nginx.conf server { listen ; modsecurity on; //启动mod ...
- 1.Maven之(一)Maven是什么
转自:https://blog.csdn.net/xhxmister/article/details/79409208 首先,Maven的正确发音是[ˈmevən],而不是“马瘟”以及其他什么瘟.Ma ...
- C#List<string>和string[]之间的相互转换
一.LIST概述 所属命名空间:System.Collections.Generic public class List<T> : IList<T>, IColle ...
- Atcoder ABC 071 C,D
C - Make a Rectangle Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement W ...
- Java反射之getInterfaces()方法
今天学习Spring3框架,在理解模拟实现Spring Ioc容器的时候遇到了getInterfaces()方法.getInterfaces()方法和Java的反射机制有关.它能够获得这个对象所实现的 ...