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万到 ...
随机推荐
- 8. php回调后门
中国菜刀下载,基于原版中国菜刀优化版20160309. 下载地址: http://pan.baidu.com/s/1jHoJxHW China chopper http://pan.baidu.com ...
- matlab新手入门(三)(翻译)
数组索引 MATLAB®中的每个变量都是一个可以容纳多个数字的数组.当您要访问阵列的选定元素时,请使用索引.例如,考虑4乘4A: A = magic(4) A = 16 2 3 13 5 ...
- 2018ACM山东省赛 Games(dp取数)
Games Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description Alice and Bob ...
- C++ - main()函数参数
main()函数及其参数说明 main()函数主要形式: int main(void) int main(int argc, char *argv[]) = int main(int argc, ch ...
- ICPC 2016 China Final J. Mr.Panda and TubeMaster【最大费用最大流】
有一种限制下界强制选的,但是也可以不用 把每个格点拆成两个,一个连s一个连t,对于不是必选的连中间连流量1费用0边表示不选,然后黑白染色,黑点连横着白点连竖着,边权就是这条水管的权值,然后跑最大费用最 ...
- 静态文件与APP
目录 静态文件的配置和使用 什么是静态文件? 为什么使用静态文件 如何配置,使用静态文件 静态文件相关(动态配置) app创建预注册 app指什么? 创建一个APP 注册app app文件作用 app ...
- nodejs ejs 引擎脱离express使用
之前用ejs都是使用express创建项目,然后在app.js中配置好的ejs直接使用即可,但是最近项目中使用的手工路由模式,脱离了express,不知道怎么用了,去扒ejs的网站,各种资料,也是懵懵 ...
- SPA单页应用前后分离微信授权
项目基于微信公众号开发,业务完全依赖微信授权,也就是用户进入页面已经完成授权获取到用户的OpenId. 需要有一个授权中间页:author.vue 基本实现思路: 无论使用哪个url进入页面都会先触发 ...
- 1.函数的结构,调用,传参,形参,实参,args,kwargs,名称空间,高阶函数
1.函数的初识 初始函数 获取任意一个字符串的元素的个数 s1='dsjdkjkfefenga' count=0 for i in s1: count+=1 print(count) 获取列表的元素的 ...
- Unity---协程的简单使用
1.作用 协程的作用一共有两点: 延时执行代码. 在某项操作完后再执行代码. 就是控制代码在特性的时间执行. 2.协程和线程的区别 协程不是异步,不需要考虑同步和锁问题 线程避免了无意义的调度,提高了 ...