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. 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的更多相关文章
- UVa 210 Concurrency Simulator (双端队列+模拟)
题意:给定n个程序,每种程序有五种操作,分别为 var = constant(赋值),print var (打印), lock, unlock,end. 变量用小写字母表示,初始化为0,为程序所公有( ...
- Java 集合深入理解(10):Deque 双端队列
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 什么是 Deque Deque 是 Double ended queue (双端队列) 的缩写,读音和 deck 一样,蛋 ...
- UVA 246 - 10-20-30 (模拟+STL)
UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...
- UVA 246 10-20-30
题意: 给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,如果有牌堆形成了以下3种情况(按顺序判断):1.头两张+尾一张和为10或20或30.2.头一张+尾两张和为10或20或30. ...
- “取出数据表中第10条到第20条记录”的sql语句+selecttop用法
1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...
- “取出数据表中第10条到第20条记录”的sql语句+select top 使用方法
1.首先.select top使用方法: 參考问题 select top n * from和select * from的差别 select * from table -- 取全部数据.返回无序集合 ...
- 出票系统:根据淡旺季的月份和年龄,打印票价[课后练习] 出票系统:根据淡旺季的月份和年龄,打印票价[课后练习] 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 {// 出票系统:根据淡旺季的月份和年龄,打印票价[课后 ...
- 《java入门第一季》之HashSet小案例:获取10个1至20的随机数,要求随机数不能重复
这是基于HashSet集合的唯一性. /* * 编写一个程序,获取10个1至20的随机数,要求随机数不能重复. * * 分析: * A:创建随机数对象 * B:创建一个HashSet集合 ...
- 题目:企业发放的奖金根据利润提成。 利润(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万到 ...
随机推荐
- 面试问题 ---C#中的委托
一.C#委托是什么的? 在正式介绍委托之前,我想下看看生活中委托的例子——生活中,如果如果我们需要打官司,在法庭上是由律师为我们辩护的,然而律师真真执行的是当事人的陈词,这时候律师就是一个委托对象,当 ...
- 3DMAX可编辑多边形常用命令-桥
桥命令可以连接连个面 下图两个cube(可编辑多边形)已经被附加到一起,选中相对的两个面,点击桥 结果
- JAVA编写的断点续传小程序
上了一周的课,今天终于可以休息了,太棒了,今天闲着无聊使用java语言写了一个断点续传的小程序来分享给大家, 首先要下载个用于网络请求的框架:我这里给出地址,是用的Apache的HttpClient: ...
- Spark 学习(二)
继续学习spark 认真查看了一下${SPARK_HOME}/bin/pyspark 的脚本,原来开启spark 的python 交互挺简单的. 主要操作 export PYTHONPATH=${SP ...
- JQuery序列化表单serialize() 以及 serializeArray()
都是利用form表单传递数据的 1.serialize()方法 描述:序列化表单内容为字符串,用于Ajax请求. 数据类似于这种: FirstName=Bill&LastName=Gates ...
- 【poj3764】The xor-longest Path
The xor-longest Path Description In an edge-weighted tree, the xor-length of a path p is defined as ...
- hdu4570-区间dp
这道题的题意不是一般的难懂啊,各种查字典都没理解,还是没忍住去看了别人的博客,没想到题很简单,1-n内划分若干个区间,使的每个区间和最小,每个区间的区间和是:区间开头的数*2^区间长度. 区间dp # ...
- CountDownLatch MyUncaughtExceptionHandler
package com.yd.wmsc.util; import java.text.SimpleDateFormat; import java.util.Date; import java.util ...
- 一文读懂DDD
何为DDD DDD不是架构设计方法,不能把每个设计细节具象化,DDD是一套体系,决定了其开放性,体系中可以用任何一种方法来解决这些问题,但是如果一些关键问题没有具体方案落地,可能让团队无所适从. 有的 ...
- 《javascript设计模式》笔记之第十章 和 第十一章:门面模式和适配器模式
第十章:门面模式 一:门面模式的作用 简化已有的api,使其更加容易使用 解决浏览器的兼容问题 二:门面模式的本质 门面模式的本质就是包装已有的api来简化操作 三:门面模式的两个简单例子 下面这 ...