题解 CF546C 【Soldier and Cards】
思路
是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素!
代码
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn=+;
int main()
{
int n;
cin>>n;
queue<int>a;//队列
queue<int>b;
int x,y;
cin>>x;
for(int i=;i<x;i++)
{
int x;
cin>>x;
a.push(x);
}
cin>>y;
for(int i=;i<y;i++)
{
int y;
cin>>y;
b.push(y);
}
int sum=;//记录步数
bool flag=;//判断输赢以及游戏是否结束
while(sum<=maxn)
{
int u=a.front();a.pop();
int v=b.front();b.pop();
sum++;
if(u>v)
{
a.push(v);//U比V大时
a.push(u);
}
else
{
b.push(u);//U比V小时
b.push(v);
}
if(a.size()==&&b.size()==)//游戏结束
break;
if(a.size()==)
{
printf("%d %d\n",sum,);
flag=;
}
if(b.size()==)
{
printf("%d %d\n",sum,);
flag=;
}
if(flag==)break;
}
if(flag==)printf("-1\n");
return ;
}
是不是很简单呢?
题解 CF546C 【Soldier and Cards】的更多相关文章
- [CF546C] Soldier and Cards - 模拟
两个人玩牌,首先两个人都拿出自己手牌的最上面的进行拼点,两张拼点牌将都给拼点赢得人,这两张牌放入手牌的顺序是:先放对方的牌再放自己的.若最后有一个人没有手牌了,那么他就输了,求输出拼点的次数和赢得人的 ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards 水题
C. Soldier and Cards Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546 ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- 【codeforces 546C】Soldier and Cards
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 队列 Soldier and Cards
Soldier and Cards 题目: Description Two bored soldiers are playing card war. Their card deck consists ...
- CF Soldier and Cards (模拟)
Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- cf 546C Soldier and Cards
题目链接:C. Soldier and Cards Two bored soldiers are playing card war. Their card deck consists of exact ...
- C - Soldier and Cards
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Two bo ...
- 【CodeForces - 546C】Soldier and Cards (vector或队列)
Soldier and Cards 老样子,直接上国语吧 Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌, ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
随机推荐
- Java 方法的重写
方法重写规则: 1.子类要重写的方法与父类方法具有完全相同的返回类型+方法名称+参数列表: 2.子类要重写的方法的访问权限大于或者等于父类方法的访问权限: 3.子类要重写的方法不能抛出比父类方法更大的 ...
- MongoDB-比较符及修改器
数学比较符 $lt 小于 $lte 小于等于 $gt 大于 $gte 大于等于 $eq 等于 $ne 不等于 所有数据 > db.stutent.find() }) { "_id&qu ...
- Hearthstone AI
search keyword `machine learning hearthstone` with google I am a legend: Hacking Hearthstone with ma ...
- vue+大文件断点续传
根据部门的业务需求,需要在网络状态不良的情况下上传很大的文件(1G+).其中会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长,请求超时:3,传输中断,必须重新上传导致前功尽弃.解 ...
- Python实现的选择排序算法原理与用法实例分析
Python实现的选择排序算法原理与用法实例分析 这篇文章主要介绍了Python实现的选择排序算法,简单描述了选择排序的原理,并结合实例形式分析了Python实现与应用选择排序的具体操作技巧,需要的朋 ...
- 工具的更新换代 总是要折腾一下Windows10下Java Web 开发环境的配置
Windows10下Java Web 开发环境的配置 由于经常性遗忘,所以整理一下 Java Web 开发环境的搭建与配置,利人利己 主要分为以下几步,需要可以挑着看 Windows下 JDK 的下载 ...
- pip安装软件报错 utf-8 code can't decode byte 0xcf in position7
pip安装软件报错 utf-8 code can't decode byte 0xcf in position7 根据错误提示的路径找到__init__.py文件 根据错误提示的最后几句话找到对应的行 ...
- php自定义错误处理函数
function myErrorHandler($errno, $errstr, $errfile, $errline) { echo "<b>Custom error:< ...
- error_reporting函数引起的error_log配置失效的问题
由于项目代码中大量使用了error_reporting(0);导致php.ini中的error_log失效,不记录错误日志, 导致调试起来非常不便,耗费大量的时间,所以在php.ini的配置中禁止掉e ...
- Go语言中使用切片(slice)实现一个Vector容器
Go语言中的切片(slice)和一些内置函数能实现其他语言容器类Array.Vector的功能,但是Go内置语言包container里只提供了list.heap.ring三种容器,缺少vector容器 ...