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万到 ...
随机推荐
- go实现冒泡排序和快速排序
项目结构 冒泡排序算法,源文件bubblesort.go package bubblesort // 冒泡排序 func BubbleSort(values []int) { for i := 0; ...
- 怎么将vim的剪切版设置成系统的剪切版
如果你用vim敲完了代码,怎么把代码提交到ACMoj的粘贴版上呢. 这是个问题. 去网上查了一下,首先有人说可以在vimrc里面添加 set clipboard=unnamed 我试了一下,没有效果. ...
- Jsoncpp写“鱘”的json数据,报错。
最近在用Json::FastWriter生成json数据时,发现一个问题.含有“鱘”字的json字段会多出一个斜杠,不知道是不是编码的问题. C++要使用JSON来解析数据,一般采用jsoncpp. ...
- Ext.apply(src,apply) 和 Ext.applyIf(src,apply)比较(转)
Ext.onReady(function(){ /* * Ext.apply(src,apply) 和 Ext.applyIf(src,apply) 两个方法的使用和区别比较 */ //Ext.app ...
- 不使用三方包时,如何在ThinkSNS中建立优雅的用户权限管理
什么是ThinkSNS ? ThinkSNS(简称TS),一款全平台综合性社交系统,为国内外大中小企业和创业者提供社会化软件研发及技术解决方案,目前最新版本为ThinkSNS+(简称TS+).Thin ...
- JavaScript进阶 - 第2章 你要懂的规则(JS基础语法)
第2章 你要懂的规则(JS基础语法) 2-1什么是变量 什么是变量? 从字面上看,变量是可变的量:从编程角度讲,变量是用于存储某种/某些数值的存储器.我们可以把变量看做一个盒子,盒子用来存放物品,物品 ...
- virtualenv模块安装
依赖包管理模块(virtualenv) virtualenv是Python的虚拟环境,可以在同一台PC隔离不同的python开发环境.virtualenv可以创建一个隔离的python环境(沙盒).使 ...
- 送气球.jpg(模拟)
链接:https://ac.nowcoder.com/acm/contest/318/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- String 中配置文件详解
<context:component-scan>使用说明 http://blog.csdn.net/chunqiuwei/article/details/16115135
- 043 Multiply Strings 字符串相乘
给定两个以字符串表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积.注意: num1 和 num2 的长度均小于110. num1 和 num2 均只包含数字 0 ...