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. 2. docker 容器的管理(创建、查看、启动、终止、删除)

    一.创建 docker create:创建容器,处于停止状态. centos:latest:centos容器:最新版本(也可以指定具体的版本号). 本地有就使用本地镜像,没有则从远程镜像库拉取. 创建 ...

  2. 使用WSAIoctl获取AcceptEx函数指针 [转]

    Winsock2的其他供应商不一定会实现AcceptEx函数.同样情况也包括的其他Microsoft的特定APIs如TransmitFile,GetAcceptExSockAddrs以及其他Micro ...

  3. Jmeter获取登录的token

    这是之前在公司一个实际的接口性能测试项目中,遇到的问题.现在有空总结一下.我们所做的项目一般都需要先登录,这个时候就需要把登录和所要测试的接口分为两个事务,Jmeter中即为事务控制器. 1.首先,我 ...

  4. 2017-9-13 NOIP模拟赛[xxy]

    全排列 (permutation.cpp/c/pas)Description从 n 个不同元素中任取 m(m≤n)个元素,按照一定的顺序排列起来,叫做从 n个不同元素中取出 m 个元素的一个排列.当 ...

  5. Java基础--环境配置、简介

    一.环境配置 1.傻瓜式安装JDK,若提示安装JRE,将其置于JDK同一安装目录即可. 2.配置JAVA_HOME, 指向JDK的安装目录.比如 JAVA_HOME  = %JDK安装目录% 3.配置 ...

  6. ios 实现 cell 的动态高度

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { Mes ...

  7. [转] ios数组基本用法和排序

    http://blog.csdn.net/daiyelang/article/details/18726947 1.创建数组 // 创建一个空的数组 NSArray *array = [NSArray ...

  8. Awesome Blockchain 区块链技术导航

    区块链技术导航:收集整理最全面最优质的区块链(BlockChain)技术开发相关资源. 以后找不到文档资料的时候去导航站看看. 先亮个像,我长这样: 导航站内容 区块链开发所涉及的资源: 如 项目白皮 ...

  9. url、src与href属性的区别

    http://blog.csdn.net/rickgreen/article/details/54943500

  10. 【aspnetcore】抓取远程图片

    找到要抓取的图片地址:http://i.imgur.com/8S7OaEB.jpg 抓取的步骤: 请求图片路径 获取返回的数据 将数据转换为stream 将stream转换为Image 保存Image ...