Input

Each input set consists of a sequence of 52 integers separated by spaces and/or ends of line. The integers represent card values of the initial deck for that game. The first integer is the top card of the deck. Input is terminated by a single zero (0) following the last deck.

Output

For each input set, print whether the result of the game is a win, loss, or a draw, and print the number of times a card is dealt before the game results can be determined. (A draw occurs as soon as the state of the game is repeated.) Use the format shown in the ``Sample Output" section.

Sample Input

2 6 5 10 10 4 10 10 10 4 5 10 4 5 10 9 7 6 1 7 6 9 5 3 10 10 4 10 9 2 1
10 1 10 10 10 3 10 9 8 10 8 7 1 2 8 6 7 3 3 8 2
4 3 2 10 8 10 6 8 9 5 8 10 5 3 5 4 6 9 9 1 7 6 3 5 10 10 8 10 9 10 10 7
2 6 10 10 4 10 1 3 10 1 1 10 2 2 10 4 10 7 7 10
10 5 4 3 5 7 10 8 2 3 9 10 8 4 5 1 7 6 7 2 6 9 10 2 3 10 3 4 4 9 10 1 1
10 5 10 10 1 8 10 7 8 10 6 10 10 10 9 6 2 10 10
0

Sample Output

Win : 66
Loss: 82
Draw: 73 写这题算是学了deque的用法,移动牌堆还是类似上题的写法,用pos数组建一个位置到堆的映射,要注意的是,去除一个堆以后下标要自减,以保证下次访问到当前位置的堆,这点是我写的时候没注意到,调试了好久,尴尬。
学了resize和reserve的区别,这两个和效率有关还是值得注意的。记得resize完以后再赋值。
如果是自己写的class,想用set判重,要重载操作符<,可用memcpy实现。

/*
Created by Rey Chen on 2015.7.4
*/

#include<cstdio>
#include<queue>
#include<set>
#include<vector>
using namespace std;
const int maxn = ;
char *ans[] = {"Draw:", "Loss:", "Win :"}; vector<deque<int> >s();
deque<int> &hand = s[]; int pos[];
int plSz;
int step; inline bool pick(deque<int> & x)
{
int n = x.size();
int sum; if(sum = x[] + x[] + x[n-], sum == || sum == || sum == ){//
hand.push_back(x[]); hand.push_back(x[]); hand.push_back(x[n-]);
x.pop_front(); x.pop_front(); x.pop_back();
return true;
}
if(n>){
if(sum = x[]+x[n-]+x[n-], sum == || sum == || sum == ) {
hand.push_back(x[]); hand.push_back(x[n-]); hand.push_back(x[n-]);
x.pop_front(); x.pop_back(); x.pop_back();
return true;
}
if(sum = x[n-]+x[n-]+x[n-], sum == || sum == || sum == ) {
hand.push_back(x[n-]); hand.push_back(x[n-]); hand.push_back(x[n-]);
x.pop_back(); x.pop_back(); x.pop_back();
return true;
}
} return false;
} int sovle()
{
set<vector<deque<int> > > vis;
vis.insert(s);
int t,id;
for(;;){
for(int i = ;i < plSz; i++) {
if(hand.empty()) return ;
t = hand.front(); hand.pop_front();
step++;
id = pos[i];
s[id].push_back(t);
while(s[id].size()>= && pick(s[id])) {
if(s[id].empty()) {
plSz--;
if(plSz == ) return ;
for(int j = i;j < plSz;j++) {//移动堆
pos[j] = pos[j+];
}
i--;//访问移动后这堆
}
}
if(vis.count(s) == ) vis.insert(s);
else return ;
}
}
return ;
} bool read()
{
int t;
scanf("%d",&t);
if(t == ) return false; step = ;
for(int i = ;i <;i++)
s[i].clear();
hand.resize(); for(int i = ;i <;i++)
pos[i] = i+;
plSz = ; deque<int>:: iterator it;
hand[] = t;
for(it = hand.begin(), it++; it != hand.end() ; it++)
scanf("%d",&t), *it = t;
return true;
} int main()
{
// freopen("in.txt","r",stdin);
while(read()) {
int flag = sovle();
printf("%s %d\n",ans[flag],step);
}
return ;
}
												

UVA 246 10-20-30 10-20-30游戏 模拟+STL双端队列deque的更多相关文章

  1. UVa 210 Concurrency Simulator (双端队列+模拟)

    题意:给定n个程序,每种程序有五种操作,分别为 var = constant(赋值),print var (打印), lock, unlock,end. 变量用小写字母表示,初始化为0,为程序所公有( ...

  2. Java 集合深入理解(10):Deque 双端队列

    点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 什么是 Deque Deque 是 Double ended queue (双端队列) 的缩写,读音和 deck 一样,蛋 ...

  3. UVA 246 - 10-20-30 (模拟+STL)

    UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...

  4. UVA 246 10-20-30

    题意: 给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,如果有牌堆形成了以下3种情况(按顺序判断):1.头两张+尾一张和为10或20或30.2.头一张+尾两张和为10或20或30. ...

  5. “取出数据表中第10条到第20条记录”的sql语句+selecttop用法

    1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...

  6. “取出数据表中第10条到第20条记录”的sql语句+select top 使用方法

    1.首先.select top使用方法: 參考问题  select top n * from和select * from的差别 select * from table --  取全部数据.返回无序集合 ...

  7. 出票系统:根据淡旺季的月份和年龄,打印票价[课后练习] 出票系统:根据淡旺季的月份和年龄,打印票价[课后练习] 4 10旺季: 4 10旺季: 成人(18-60) : 60 成人(18-60):60 儿童(<18) :半价 儿童(<18):半价 老人(>60) :1/3 老人(>60):1/3 淡季: 淡季: 成人: 40 成人:40 其他: 20 其他:20

    用if适合新手练习 package LianXiTi;import java.util.Scanner;public class first2 {// 出票系统:根据淡旺季的月份和年龄,打印票价[课后 ...

  8. 《java入门第一季》之HashSet小案例:获取10个1至20的随机数,要求随机数不能重复

    这是基于HashSet集合的唯一性. /*  * 编写一个程序,获取10个1至20的随机数,要求随机数不能重复.  *   * 分析:  * A:创建随机数对象  * B:创建一个HashSet集合 ...

  9. 题目:企业发放的奖金根据利润提成。 利润(I)低于或等于10万元时,奖金可提10%; 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%; 20万到40万之间时,高于20万元的部分,可提成5%; 40万到60万之间时高于40万元的部分,可提成 3%; 60万到100万之间时,高于60万元的部分,可提成1.5%; 高于100万元时,超过

    题目:企业发放的奖金根据利润提成. 利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%: 20万到 ...

随机推荐

  1. SQL Server(三)

    一.数据库操作 create database 数据库名称 ——创建drop database 数据库名称 ——删除use 数据库名称 ——使用go 两条SQL语句之间分隔 二.表的操作 create ...

  2. Open-source Tutorial - Json.NET

    JSON 简介 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种由道格拉斯·克罗克福特构想和设计.轻量级的数据交换语言,该语言以易于让人阅读的文字 ...

  3. 数据库路由中间件MyCat - 源代码篇(6)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 3.3 AbstractConnection: 3.3.2 NIOHandler NIOHa ...

  4. 使用ASP.NET Core实现Docker的HealthCheck指令

     写在前面 HealthCheck 不仅是对应用程序内运行情况.数据流通情况进行检查, 还包括应用程序对外部服务或依赖资源的健康检查. 健康检查通常是以暴露应用程序的HTTP端点的形式 实施,可用于配 ...

  5. solidity 学习笔记(6)call 函数

    call() 方法 call()是一个底层的接口,用来向一个合约发送消息,也就是说如果你想实现自己的消息传递,可以使用这个函数.函数支持传入任意类型的任意参数,并将参数打包成32字节,相互拼接后向合约 ...

  6. 洛谷P1005 矩阵取数游戏

    P1005 矩阵取数游戏 题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次 ...

  7. php高并发之opcache

    今天工作的时候接触到客户的一台服务器,业务逻辑比较简单 .估算pv在120w左右吧,用的是阿里云2c4g的服务器.一大早就开始卡顿了,登陆服务器后查看负载到了八九十. 之后就想办法调整一下吧.突然想起 ...

  8. symbol lookup error: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard 错误

    通过更新glib2包修复.(yum update glib2)即可 拿走不谢,我也找得好辛苦!!!

  9. jsonpath 求和

    { "price": [ 1.0, 2.0 ] } $..price.sum() 以下表达式

  10. 简单记录下HTTPS中的SSL

    大概思路 大概思路是混合加密的方式,即对称加密方式混合非对称加密方式. 非对称加密会更加安全,功能也更强大,但他复杂而且速度慢. 对称加密速度快,但要保证这个公共密钥的正确性和真实性. 所以两者结合, ...