思路

是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素!

代码

 #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】的更多相关文章

  1. [CF546C] Soldier and Cards - 模拟

    两个人玩牌,首先两个人都拿出自己手牌的最上面的进行拼点,两张拼点牌将都给拼点赢得人,这两张牌放入手牌的顺序是:先放对方的牌再放自己的.若最后有一个人没有手牌了,那么他就输了,求输出拼点的次数和赢得人的 ...

  2. 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 ...

  3. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  4. 【codeforces 546C】Soldier and Cards

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 队列 Soldier and Cards

    Soldier and Cards 题目: Description Two bored soldiers are playing card war. Their card deck consists ...

  6. CF Soldier and Cards (模拟)

    Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. cf 546C Soldier and Cards

    题目链接:C. Soldier and Cards Two bored soldiers are playing card war. Their card deck consists of exact ...

  8. C - Soldier and Cards

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Two bo ...

  9. 【CodeForces - 546C】Soldier and Cards (vector或队列)

    Soldier and Cards 老样子,直接上国语吧  Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌, ...

  10. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

随机推荐

  1. 数据结构实验之栈与队列六:下一较大值(二)(SDUT 3333)

    #include <bits/stdc++.h> using namespace std; int a[1000006]; int b[1000006]; int sta[100006]; ...

  2. 2019.6.24 校内测试 NOIP模拟 Day 2 分析+题解

    看到Day 2的题真的想打死zay了,忒难了QwQ~ T1 江城唱晚 这明显是个求方案数的计数问题,一般的套路是DP和组合数学. 正如题目中所说,这个题是一个 math 题.      ----zay ...

  3. hive 常用参数

    hive.exec.max.created.files •说明:所有hive运行的map与reduce任务可以产生的文件的和 •默认值:100000  hive.exec.dynamic.partit ...

  4. zabbix监控windows案例

    首先在zabbix官网下载zabbix软件包:https://www.zabbix.com/ 下载完成之后,将其解压到D盘 # 配置与安装,配置zabbix agent相关配置. 找到conf下的配置 ...

  5. Qt自定义类添加qvector报错

    PtsData& PtsData::operator=(const PtsData& obj){ return *this;} PtsData::~PtsData(){ }

  6. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_04-freemarker基础-基础语法种类

    注释 编译一些这个模板 我的IDEA里面,是重新编译 刷新页面 注释.插值.FTL.文本

  7. Spring事务管理4-----声明式事务管理(2)

    声明式事务管理  基于AspectJ的 XML 方式配置 通过对事务管理器TransactionManager配置通知(增强),然后再配置切点和切面,详细见applicationContext.xml ...

  8. PHP 调用C# WebService

    在VS2010中新建WebService:Finance.asmx 代码如下: using System.Web.Services; namespace WebTest.WebService { // ...

  9. How To Use Rocketbots As A Dialogflow CRM

    Ever wished you had a CRM for Dialogflow? We did too, so we built one. This is a best practices arti ...

  10. 【Python】机器学习之单变量线性回归 利用批量梯度下降找到合适的参数值

    [Python]机器学习之单变量线性回归 利用批量梯度下降找到合适的参数值 本题目来自吴恩达机器学习视频. 题目: 你是一个餐厅的老板,你想在其他城市开分店,所以你得到了一些数据(数据在本文最下方), ...