UVA 246 - 10-20-30

题目链接

题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断):

1、头两张+尾一张和为10或20或30

2、头一张+尾两张和为10或20或30

3、尾三张和为10或20或30

就把这三张牌拿走,放到总牌堆底(这步要不断运行直到不再满足条件或牌堆没了)

假设有一个牌堆由于这个操作被取完了,那么以后将不在这个位置发牌。

假设最后7个牌堆都能够消掉,那么赢,总牌堆用完,那么输,否则平(即不断循环)

问最后的输赢平,并输出步数

思路:模拟,用一个vector记录下7个牌堆和总牌堆,这样就能够用set去记录状态了,然后每一个牌堆用一个双端队列deque表示,这样满足能够从头也能够从尾巴取,不断模拟就可以

代码:

#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
using namespace std; int num, zero[8];
vector<deque<int> > piple;
set<vector<deque<int> > > vis; void init() {
vis.clear();
piple.clear();
memset(zero, 0, sizeof(zero));
for (int i = 0; i < 8; i++)
piple.push_back(deque<int>());
piple[7].push_back(num);
for (int i = 0; i < 51; i++) {
scanf("%d", &num);
piple[7].push_back(num);
}
for (int i = 0; i < 7; i++) {
int now = piple[7].front();
piple[7].pop_front();
piple[i].push_back(now);
}
} bool can(int x) {
return (x == 10 || x == 20 || x == 30);
} bool tra1(int i) {
int top1 = piple[i].front();
piple[i].pop_front();
int sum = top1 + piple[i].front() + piple[i].back();
if (can(sum)) {
piple[7].push_back(top1);
piple[7].push_back(piple[i].front());
piple[7].push_back(piple[i].back());
piple[i].pop_front();
piple[i].pop_back();
return true;
}
piple[i].push_front(top1);
return false;
} bool tra2(int i) {
int back1 = piple[i].back();
piple[i].pop_back();
int sum = back1 + piple[i].front() + piple[i].back();
if (can(sum)) {
piple[7].push_back(piple[i].front());
piple[7].push_back(piple[i].back());
piple[7].push_back(back1);
piple[i].pop_front();
piple[i].pop_back();
return true;
}
piple[i].push_back(back1);
return false;
} bool tra3(int i) {
int back1 = piple[i].back();
piple[i].pop_back();
int back2 = piple[i].back();
piple[i].pop_back();
int sum = back1 + back2 + piple[i].back();
if (can(sum)) {
piple[7].push_back(piple[i].back());
piple[7].push_back(back2);
piple[7].push_back(back1);
piple[i].pop_back();
return true;
}
piple[i].push_back(back2);
piple[i].push_back(back1);
return false;
} bool tra(int i) {
if (piple[i].size() < 3) return false;
if (tra1(i)) return true;
if (tra2(i)) return true;
if (tra3(i)) return true;
return false;
} void solve() {
int i = 0;
for (int t = 8; ; t++) {
int now = piple[7].front();
piple[7].pop_front();
piple[i].push_back(now);
while (tra(i));
if (piple[i].size() == 0)
zero[i] = 1;
i = (i + 1) % 7;
if (vis.find(piple) != vis.end()) {
printf("Draw: %d\n", t);
return;
}
vis.insert(piple);
if (piple[7].size() == 0) {
printf("Loss: %d\n", t);
return;
}
if (piple[7].size() == 52) {
printf("Win : %d\n", t);
return;
}
while (zero[i]) i = (i + 1) % 7;
}
} int main() {
while (~scanf("%d", &num) && num) {
init();
solve();
}
return 0;
}

UVA 246 - 10-20-30 (模拟+STL)的更多相关文章

  1. UVA 246 10-20-30 10-20-30游戏 模拟+STL双端队列deque

    Input Each input set consists of a sequence of 52 integers separated by spaces and/or ends of line. ...

  2. 2018.10.20 NOIP模拟 蛋糕(线段树+贪心/lis)

    传送门 听说是最长反链衍生出的对偶定理就能秒了. 本蒟蒻直接用线段树模拟维护的. 对于第一维排序. 维护第二维的偏序关系可以借助线段树/树状数组维护逆序对的思想建立权值线段树贪心求解. 代码

  3. 2018.10.20 NOIP模拟 巧克力(trie树+dfs序+树状数组)

    传送门 好题啊. 考虑前面的32分,直接维护后缀trietrietrie树就行了. 如果#号不在字符串首? 只需要维护第一个#前面的字符串和最后一个#后面的字符串. 分开用两棵trie树并且维护第一棵 ...

  4. 2018.10.20 NOIP模拟 面包(数学期望)

    传送门 把方差的式子拆开. 方差=平方的期望-期望的平方. 显然只用维护点对的个数和总方案数就行了. 利用分步的思想来统计. 要统计覆盖一个矩形(x1,y1,x2,y2)(x1,y1,x2,y2)(x ...

  5. 2019.10.20 csp-s模拟测试 lrd试题 反思总结

    赶进度赶进度,丢个代码两三句备注一下完事了. day1: 前面两道题没实际写代码怕印象不深所以描述一下大意. T1: 题目大意:给出两个数&.|.^的结果(可能只给出其中某一项或者某两项),求 ...

  6. 10.16 NOIP模拟赛

    目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...

  7. CSP 201612-3 权限查询 【模拟+STL】

    201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统用户通过授权 ...

  8. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. 10.8 wtx模拟题题解

    填坑 orz w_x_c_q w_x_c_q的模拟赛(150pts,炸了) money 题目背景: 王小呆又陷入自己的梦里.(活在梦里...) 题目描述: 王小呆是一个有梦想的小菜鸡,那就是赚好多好多 ...

随机推荐

  1. 无心插柳OR志在必得?阿里推“来往”的意图

        近年来,阿里巴巴在外围的动作确实不少,投资新浪微博.投资陌陌,配合阿里自身的一些战略调整,让人觉得这家公司似乎正在经历一场前所未有的“蜕变”.其实这也不难理解,在BAT三国演义中,任何一方都不 ...

  2. 文件atime未变问题的研究

    1. atime, ctime 以及mtime 这三个名词属于文件/文件夹的属性,存在于inode数据结构之中. 通过系统调用stat可以获取stat结构,其中包括:atime(accesstime) ...

  3. 打印log 保存log

    using UnityEngine; using System.Collections; using System.IO; using System; using System.Text; names ...

  4. [Regex Expression] Confirmative -- World bundry

    String to check: As it turns out, our potential shipmates are extremely superstitious. As such, we d ...

  5. [Cycle.js] Hyperscript as our alternative to template languages

    Usually we use template languages like Handlebars, JSX, and Jade to create. One simple way we can cr ...

  6. Linux 内核开发 - 进程空间

    1.1 虚拟内存 Linux 的系统.假设每一个任务都独立的占用内存,则实际的物理内存将非常快消耗殆尽.实际上对于前台正在执行的任务来说,所须要要的内存并不多,非常多任务基本不须要执行,也就没有必要一 ...

  7. (转)swfobject.js 详细解说

    一直想对这个应用做个总结,今天偶然百度到这个效果,为此做个笔记. 用这个js的好处: 1.IE中没有讨厌的虚框问题了.2.提供了完善的版本检测功能,如果版本不够则显示其他东西,比如图片或文字.3.易于 ...

  8. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践

    欢迎转载,转载时请保留全文及出处. Apache 2.4.7在CentOS6.4中安装配置反向代理解决单外网IP对应多个内网主机的方法实践 Apache安装 下载源程序(http://httpd.ap ...

  9. protobuf 参考资料

    Protocol Buffers 官网下载地址:https://developers.google.com/protocol-buffers/docs/downloads Protocol Buffe ...

  10. codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Beautiful Strings Vas ...