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 ...
随机推荐
- huawei校招测试题
三道题两小时. 第一题,圈住所有点的长方形,很简单略过. 第二题:奇偶排序. 奇偶排序 描述: 输入若干(不超过1000个)非负整数数字,请先取出为奇数的数字按从大到小排序,再取出偶数从小到大进行排序 ...
- c++vector简单实现
const int DEFAULT_CAP = 3; template <typename T> class vector { // int capacity; T* _data; int ...
- Facebook内部高效工作指南
文章来源: TopDigital http://news.ittime.com.cn/usershow/main?userid=2826 [IT时代网.IT时代周刊编者按]每一个人工作中都会遇到力不从 ...
- Java中的文件上传和下载
文件上传原理: 早期的文件上传机制: 在TCP/IP中.最早出现的文件上传机制是FTP.他是将文件由客户端发送到服务器的标准机制. jsp中的文件上传机制: 在jsp编程中不能使用FTP的方法来上传文 ...
- 0mq
- A Practical Introduction to Blockchain with Python
A Practical Introduction to Blockchain with Python // Adil Moujahid // Data Analytics and more http: ...
- 关于LAMP配置Let’s Encrypt SSL证书
昨天建站,买VPS,先装了LAMP,部署wordpress,测试OK了,然后才买的域名,申请SSL证书. 结果Let’s Encrypt cerbot申请证书遇到了麻烦,--apache参数怎么也识别 ...
- local_irq_disable
local_irq_disable 仅仅是 设置 当前CPU 的中断屏蔽位 disable_irq 是禁用 全部cpu 中断(只是当前irq) 如果你要禁止所有的中断该怎么办? 在2.6内核中,可以通 ...
- iOS在一个label中显示不同颜色的字体
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)]; NSMutableAttributedSt ...
- Healthy Holsteins
链接 分析:因为数据范围比较小,我们可以通过二进制枚举子集,然后找出所需饲料种数最小的并记录下来,同时记录一下路径,也就是字典序最小的 /* PROB:holstein ID:wanghan LANG ...