【习题 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,然后往全拿光推···样例过不去···后来觉得推反了 ...
随机推荐
- CentOS6.x操作系统自带的 DM Multipath(DMMP)多路径软件配置说明。
CentOS系统下的多路径软件是操作系统自带的 DM Multipath(DMMP)工具.------------------------------------------------------- ...
- [USACO07JAN]平衡的阵容Balanced Lineup RMQ模板题
Code: #include<cstdio> #include<algorithm> using namespace std; const int maxn = 50000 + ...
- Mark Compact GC (Part two :Two-Finger)
目录 Two-Finger算法 前提 概要 步骤一:移动对象 步骤二:更新指针 优缺点 表格算法 概要 步骤一:移动对象群 和 构筑间隙表格 移动对象群 构筑间隙表格 步骤二:更新指针 优缺点 Two ...
- UESTC 360 Another LCIS
Another LCIS Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on UESTC. Original ...
- qt程序实现打开文件夹
QString path=QDir::currentPath();//获取程序当前目录 path.replace("/","\\");//将地址中的" ...
- Android应用公布后的统计——百度移动统计的应用
一个App公布到各个渠道之后,我们须要採集不同渠道的一些信息,比方app在执行过程中产生的一些异常信息,app在各个android版本号的分布,以及各个app版本号的分布,各渠道的用户数,用户忠诚度等 ...
- OCP-1Z0-051-题目解析-第27题
27. Which two statements are true regarding tables? (Choose two.) A. A table name can be of any len ...
- c++值传递,指针传递,引用传递以及指针与引用的区别
值传递: 形参是实参的拷贝,改变形参的值并不会影响外部实参的值.从被调用函数的角度来说,值传递是单向的(实参->形参),参数的值只能传入, 不能传出.当函数内部需要修改参数,并且不希望这个改变影 ...
- Zabbix + Grafana
Grafana 简介 Grafana自身并不存储数据,数据从其它地方获取.需要配置数据源 Grafana支持从Zabbix中获取数据 Grafana优化了图形的展现,可以用来做监控大屏 Grafana ...
- 具有可视化的功能的一款开源软件Gource
今天为大家介绍一个非常有趣儿的开源软件,Gource可以将代码版本控制系统里面的日志全部可视化,也就是说可以看见每个成员在系统里面提交代码的行为,Gource目前支持git,hg,svn. 650) ...