queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
/*
题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌
queue容器:模拟上述过程,当次数达到最大值时判断为-1
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <cmath>
#include <queue>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int x[MAXN];
queue<int> Q1;
queue<int> Q2; int main(void) //Codeforces Round #304 (Div. 2) C. Soldier and Cards
{
int n, m1, m2;
while (scanf ("%d", &n) == )
{
while (!Q1.empty ()) Q1.pop ();
while (!Q2.empty ()) Q2.pop (); int x;
scanf ("%d", &m1);
for (int i=; i<=m1; ++i)
{
scanf ("%d", &x); Q1.push (x);
} scanf ("%d", &m2);
for (int i=; i<=m2; ++i)
{
scanf ("%d", &x); Q2.push (x);
} int cnt = ;
while (!Q1.empty () && !Q2.empty ())
{
int x = Q1.front (); int y = Q2.front ();
Q1.pop (); Q2.pop ();
if (x < y) {Q2.push (x); Q2.push (y);}
else {Q1.push (y); Q1.push (x);}
++cnt;
if (cnt == ) break;
} if (cnt == ) puts ("-1");
else
{
printf ("%d %d\n", cnt, (Q1.empty ()) ? : );
}
} return ;
} /*
4
2 1 3
2 4 2
3
1 2
2 1 3
*/
queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards的更多相关文章
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 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 ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
D. Soldier and Number Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #304 (Div. 2) E. Soldier and Traveling 最大流
题目链接: http://codeforces.com/problemset/problem/546/E E. Soldier and Traveling time limit per test1 s ...
- Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题
B. Soldier and Badges Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...
随机推荐
- Memory cycles about Block
Block keeps a strong point to all object referenced in side of them, so all object will stay in heap ...
- ArrayDeque类的使用详解
ArrayDeque是Deque接口的一个实现,使用了可变数组,所以没有容量上的限制. 同时,ArrayDeque是线程不安全的,在没有外部同步的情况下,不能再多线程环境下使用. ArrayDeque ...
- [RK3288]PMU配置(RK808)【转】
本文转载自:http://www.javashuo.com/content/p-6398007.html 硬件原理 pmic 电路原理 平台概述 RK808 PWM 介绍 驱动分析 dts 驱动流程 ...
- lock的两种方式
假设现在我们有100个数据项可以读写.有若干个线程,任何一个线程可能对任何一个数据项尽心读写. 但是,如果不同的线程在对同一个数据项进行读写,就可能发生错误.需要使用lock进行控制. 比如线程x要对 ...
- 让振动器振动起来——Vibrator的使用
AndroidManifest.xml 获取系统权限 <uses-permission android:name="android.permission.VIBRATE"/& ...
- web 基本概念辨异 —— URI 与 URL
两者的相同点: 都是唯一的,对资源(R:Resource)起到唯一的标识作用: 两者的不同点: URL 是 URI 的子集(URI 是父类,URL 是子类),是一种特定的实现形式: URI 可以是身份 ...
- POJ2689:Prime Distance(大数区间素数筛)
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- MFC之document与view实践总结
Document/View是MFC的基石,负责程序数据的管理和显示,Doculent和Viewd的关系有一档一视,一档多视和多档多视,下面将分别对实现过程中的重点知识进行总结. 1. 视图的同步更新 ...
- SQL查询速度
查询速度 https://www.cnblogs.com/ZaraNet/p/9558272.html 影响你的查询速度的原因是什么? 网速不给力,不稳定. 服务器内存不够,或者SQL 被分配的内存不 ...
- 【POJ 1061】 青蛙的约会
[题目链接] 点击打开链接 [算法] 列出同余方程,然后用exgcd求解 [代码] #include <algorithm> #include <bitset> #includ ...