思路

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

代码

 #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. centos7下glances系统监控的安装

    yum install epel* -y yum install python-pip python-devel -y yum install glances -y 启动>>glances

  2. windows游戏编程鼠标

    ①.常用鼠标消息: WM_MOUSEMOVE           鼠标移动位置 WM_LBUTTONDOWN       鼠标左键按下 WM_LBUTTONUP             鼠标左键弹起 ...

  3. Dubbo——配置

    一.配置原则 JVM 启动 -D 参数优先,这样可以使用户在部署和启动时进行参数重写,比如在启动时需改变协议的端口. XML 次之,如果在 XML 中有配置,则 dubbo.properties 中的 ...

  4. 前端逼死强迫症系列之Html

    概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...

  5. c++ 容器反转

    // reverse algorithm example #include <iostream> // std::cout #include <algorithm> // st ...

  6. 如何确定哪个SMB客户端/会话在Server 2008R2 Windows文件服务器上打开了特定文件?

    参考: http://www.kbase101.com/question/54969.html NetworkOpenedFiles v1.25  https://www.nirsoft.net/ut ...

  7. C#winform如何实现文本编辑框(TextBox)的Hint提示文字效果

    C#winform如何实现文本编辑框(TextBox)的Hint提示文字效果 private const int EM_SETCUEBANNER = 0x1501; [DllImport(" ...

  8. 关于Intel处理器架构中AVX2里Gather特性的说明

    在Intel Haswell架构里引入了Gather特性.它使得CPU可以使用向量索引存储器编址从存储器取非连续的数据元素.这些gather指令引入了一种新的存储器寻址形式,该形式由一个基地址寄存器( ...

  9. 详解用python实现简单的遗传算法

    详解用python实现简单的遗传算法 今天整理之前写的代码,发现在做数模期间写的用python实现的遗传算法,感觉还是挺有意思的,就拿出来分享一下. 首先遗传算法是一种优化算法,通过模拟基因的优胜劣汰 ...

  10. python之selenium玩转鼠标操作(ActionChains)

    前提: 一般人用selenium自动化时,会用到模拟鼠标操作的情况,像单击,双击,右击,左击啊等,这个时候我们就要用到ActionChains了. 内容: 1.ActionChains用法整理 cli ...