两个人玩牌,首先两个人都拿出自己手牌的最上面的进行拼点,两张拼点牌将都给拼点赢得人,这两张牌放入手牌的顺序是:先放对方的牌再放自己的。若最后有一个人没有手牌了,那么他就输了,求输出拼点的次数和赢得人的编号,如果一直无法结束比赛,则输出-1.

用队列模拟即可。

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define reset(x) memset(x,0,sizeof x)
#define reset3f(x) memset(x,0x3f,sizeof x) queue <int> a,b;
int n; signed main() {
cin>>n;
cin>>n;
for(int i=1;i<=n;i++) {
int t;
cin>>t;
a.push(t);
}
cin>>n;
for(int i=1;i<=n;i++) {
int t;
cin>>t;
b.push(t);
}
for(int i=1;i<=1e+6;i++) {
int p=a.front(), q=b.front();
a.pop(); b.pop();
int flag=0;
if(p>q) {
a.push(q);
a.push(p);
flag=1;
}
else {
b.push(p);
b.push(q);
flag=2;
}
if(a.size()==0 || b.size()==0) {
cout<<i<<" "<<flag<<endl;
return 0;
}
}
cout<<-1;
}

[CF546C] Soldier and Cards - 模拟的更多相关文章

  1. CF Soldier and Cards (模拟)

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

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

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

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

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

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

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

  5. 【codeforces 546C】Soldier and Cards

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

  6. 队列 Soldier and Cards

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

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

  8. cf 546C Soldier and Cards

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

  9. C - Soldier and Cards

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

随机推荐

  1. Cesium案例解析(四)——3DModels模型加载

    目录 1. 概述 2. 代码 3. 解析 4. 参考 1. 概述 Cesium自带的3D Models示例,展示了如何加载glTF格式三维模型数据.glTF是为WebGL量身定制的数据格式,在网络环境 ...

  2. OpenLayers动态测量距离和面积,并可自定义测量的线样式

    全局操作变量 /** * @description 标注弹出框 */ HtmlPopup = null; /** * @description 临时图层类数据源 */ VectorSource = n ...

  3. OpenLayers 6 学习笔记

    这个是真的学习笔记!不是教程 转载请声明:https://www.cnblogs.com/onsummer/p/12159366.html 基于openlayers 6.x api不太好查,就基于腾讯 ...

  4. openlayers6结合geoserver实现地图矢量瓦片(附源码下载)

    内容概览 1.基于openlayers6结合geoserver实现地图矢量瓦片2.源代码demo下载 效果图如下: 实现思路:利用Geoserver发布矢量切片服务,然后openlayers调用矢量瓦 ...

  5. SSH-Secure-Shell 3.2.9 build283版本,创建直接打开文件传输的快捷方式的方法

    2019-12-31 16:21:23 版本信息: 在安装目录下新建快捷方式 目标填写:"D:\SSH-Secure-Shell\SshClient.exe" /f 图标选择,系统 ...

  6. 如何在Mac和Windows PC之间无线共享文件

    有时候,我需要在Mac和PC之间无线共享文件.由于并非所有人都在使用macOS,因此无论是在办公室还是在家里,这种情况都会发生.尽管并非一帆风顺,但有一种无需任何第三方应用程序即可弥合差距的方法. 根 ...

  7. junit 运行(eclipse + IDEA)

    记得刚用IDEA  开发的时候, 什么都还不熟,以为junit 运行还跟eclipse 一样, 结果试了后才知道是不一样的. 现在刚好写junit 相关的,也就都记录下来吧 Eclipse:eclip ...

  8. intellji IDEA 2019版激活码(亲测可用 2019年10月14日08:53:54)

    MNQ043JMTU-eyJsaWNlbnNlSWQiOiJNTlEwNDNKTVRVIiwibGljZW5zZWVOYW1lIjoiR1VPIEJJTiIsImFzc2lnbmVlTmFtZSI6I ...

  9. CentOS7配置ftp

    1.下载vsftpd yum install -y vsftpd 2.设置开机自启动 systemctl enable vsftpd.service 3.启动 systemctl start vsft ...

  10. P2256 一中校运会之百米跑

    ----------------------- 题目链接:MIKU --------------------- 我现在发现找BUG的最好方法————喝水 喝一次找一个,喝两次A道题 --------- ...