[CF546C] Soldier and Cards - 模拟
两个人玩牌,首先两个人都拿出自己手牌的最上面的进行拼点,两张拼点牌将都给拼点赢得人,这两张牌放入手牌的顺序是:先放对方的牌再放自己的。若最后有一个人没有手牌了,那么他就输了,求输出拼点的次数和赢得人的编号,如果一直无法结束比赛,则输出-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 - 模拟的更多相关文章
- CF Soldier and Cards (模拟)
Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- 【CodeForces - 546C】Soldier and Cards (vector或队列)
Soldier and Cards 老样子,直接上国语吧 Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌, ...
- 【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 ...
- 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 ...
- 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 ...
随机推荐
- 分享8个laravel模型时间戳使用技巧
默认情况下,Laravel Eloquent 模型默认数据表有 created_at 和 updated_at 两个字段.当 然,我们可以做很多自定义配置,实现很多有趣的功能.下面举例说明. 1. 禁 ...
- 2020年如何成为一个高级AVA架构师(50W~100W年薪)
2020年如何成为一个高级AVA架构师(50W~100W年薪)
- 浅谈background的用法
div css 背景样式background属性 一.语法及参数 1.语法:background : background-color(颜色) || background-image(图片地址) || ...
- MRAM技术进入汽车应用
在整个地址空间范围内读写各种类型的数据.通常MRAM的操作和时序类似于32位微控制器的规范和时序.与DLFASH相比,当今的非易失性存储器可以接受MRAM设备的性能和吞吐量. 与当今的DFLASH相比 ...
- [USACO19FEB]Painting the Barn G
题意 \(n\)个矩阵\((0\le x_1,y_1,x_2,y_2\le 200)\),可交,可以再放最多两个矩阵(这两个矩阵彼此不交),使得恰好被覆盖\(k\)次的位置最大.\(n,k\le 10 ...
- idea 阿波罗(apollo)设置
项目启动时需要配置环境
- PHP Help Guideds
how does php work with Apache? https://stillat.com/blog/2014/04/02/how-does-php-work-with-the-web-se ...
- linux查看硬件、系统信息
查看机器型号等 dmidecode 是一个读取电脑 DMI(桌面管理接口(Desktop Management Interface))表内容并且以人类可读的格式显示系统硬件信息的工具.这个表包含系统硬 ...
- java如何在静态方法中访问类的实例成员
类的静态方法是不能直接访问实例的成员的,它只能访问同类的静态成员.访问实例的成员的话,可以参考一下这个方法,那就是把静态方法的参数设置为类的实例,这样通过参数传递的方式就可以访问实例的成员了,例子如下 ...
- array every
every() 方法测试一个数组内的所有元素是否都能通过某个指定函数的测试.它返回一个布尔值.