【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

链表模拟即可。
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的更多相关文章

  1. ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

  2. UVa 127 - "Accordian" Patience

    题目:52张扑克,从左到右在平面上排列,按着如下规则处理: 1.按照从左到右的顺序,如果一张牌和左边的第一张或者第三张匹配,就把它放到对应的牌上面. 2.如果可以移动到多个位置,移动到最左端的牌上面. ...

  3. 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 ...

  4. [刷题]算法竞赛入门经典(第2版) 6-9/UVa127 - "Accordian" Patience

    题意:52张牌排一行,一旦出现任何一张牌与它左边的第一张或第三张"匹配",即花色或点数相同,则须立即将其移动到那张牌上面,将其覆盖.能执行以上移动的只有压在最上面的牌.直到最后没有 ...

  5. ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

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

    UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...

  7. UVa 1637 - Double Patience(概率DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVa 170 - Clock Patience

    题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上, 从中间组最上面一张牌開始.翻过来设为当前值,然后取当前值相应组中最上面的背过去的牌翻过 ...

  9. UVA 1637 Double Patience

    题意:36张扑克,平分成9摞,两张数字一样的可以拿走,每次随机拿两张,问能拿光的概率. 解法:记忆化搜索,状态压缩.一开始我想在还没拿的时候概率是1,然后往全拿光推···样例过不去···后来觉得推反了 ...

随机推荐

  1. Git学习总结(5)——搭建Git简易高效服务器

    1. mysysgit+gitblit安装流程 1.1资源  需先下载好的资源(公司用的1.6,1.7+请自行匹配对应的mysysgit+gitblit):  jdk1.6  Git-1.8.4-pr ...

  2. xwiki操作手册

    Xwiki官网:http://www.xwikichina.com/xwiki/bin/view/Main/中文官网. 1   用户管理 1.1    添加新用户 用户管理需要管理员权限,管理员登陆后 ...

  3. Safe and efficient allocation of memory

    Aspects of the present invention are directed at centrally managing the allocation of memory to exec ...

  4. Swift vs C# Go OC

    Swift vs C#    mod=view&aid=21" target="_blank">http://www.swifthumb.com/porta ...

  5. 【Django】Form组件

    目录 Form组件介绍 常用字段与插件 Form组件中所有内置字段 从数据库中获取数据 校验示例 检验手机号是否合法 方式一(基本操作) 方式二(自定义验证规则) 方式三(利用钩子) 验证密码一致性 ...

  6. hostname---显示和设置系统的主机

    hostname命令用于显示和设置系统的主机名称.环境变量HOSTNAME也保存了当前的主机名.在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名. ...

  7. IntelliJ IDEA如何导入maven结构的web工程

    第一步:打开一个现有(也可以不打开,直接用import选择Maven类型)的IntelliJ IDEA工程,点击菜单的"File"->"new"-> ...

  8. PatentTips - Improving security in a virtual machine host

    BACKGROUND Computer viruses are a common problem for computer users. One typical mode of attack is t ...

  9. Nio学习3——基础模型:多路复用模型

    Reactor模式和NIO 本文可看成是对Doug Lea Scalable IO in Java一文的翻译. 当前分布式计算 Web Services盛行天下,这些网络服务的底层都离不开对socke ...

  10. 源代码看CoordinatorLayout.Behavior原理

    在上一篇博客CoordinatorLayout高级使用方法-自己定义Behavior中,我们介绍了怎样去自己定义一个CoordinatorLayout的Behavior.通过文章也能够看出Behavi ...