CodeForces 546C(队列)
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Sample Input
4
2 1 3
2 4 2
6 2
3
1 2
2 1 3
-1
#include<iostream>
#include<queue>
using namespace std;
const int N=;
queue <int>x,y;
int main()
{
int i,t,a,b,n,m;
cin>>t;
cin>>n;
for( i=; i<n; i++)
{
cin>>a;
x.push(a);
}
cin>>m;
for( i=; i<m; i++)
{
cin>>b;
y.push(b);
}
int s=;
while(!x.empty()&&!y.empty())
{
s++;
if(s>N) break;
int q=x.front();
int p=y.front();
x.pop();
y.pop();
if(q<p)
{
y.push(q);
y.push(p);
}
if(q>p)
{
x.push(p);
x.push(q);
}
}
if(x.empty())
cout<<s<<" "<<""<<endl;
else if(y.empty())
cout<<s<<" "<<""<<endl;
else cout<<"-1"<<endl; return ;
}
CodeForces 546C(队列)的更多相关文章
- 【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 ...
- codeforces 704A (队列模拟) Thor
题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...
- CodeForces 450A 队列
Description There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let ...
- codeforces546C
Soldier and Cards CodeForces - 546C Two bored soldiers are playing card war. Their card deck consist ...
- 「日常训练」 Soldier and Cards (CFR304D2C)
题意 (Codeforces 546C) 按照指定的规则打牌,问谁胜或无穷尽. 分析 又是一条模拟,用set+queue(这里手写了)处理即可.注意到两种局势"1 234"和&qu ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- Codeforces Beta Round #6 (Div. 2 Only) 单调队列
题目链接: http://codeforces.com/contest/6/problem/E E. Exposition time limit per test 1.5 secondsmemory ...
随机推荐
- [Java] JavaMail 简单案例
网易提供了免费的 SMTP / POP3服务,可用于编程测试,详情见 什么是POP3.SMTP和IMAP? 只需要拥有一个网易邮箱账号,并开启该账号的 SMTP / POP3 功能,便可以通过程序发送 ...
- 简单的FIRST+集演示程序
/* * 该程序用于计算某个非终结符的 FIRST+ 集合 * RexfieldVon * 2013年6月30日16:02:47 */ #include <stdio.h> #includ ...
- python 解析xml 文件: SAX方式
环境 python:3.4.4 准备xml文件 首先新建一个xml文件,countries.xml.内容是在python官网上看到的. <?xml version="1.0" ...
- python通过SMTP发送邮件失败,报错505/535
python通过SMTP发送邮件失败:错误1:smtplib.SMTPAuthenticationError: (550, b'User has no permission') 我们使用pyth ...
- Python字符串连接的5种方法
总结了一下Python字符串连接的5种方法: 加号 第一种,有编程经验的人,估计都知道很多语言里面是用加号连接两个字符串,Python里面也是如此直接用 "+" 来连接两个字符串: ...
- erlang mnesia数据库设置主键自增
Mnesia是erlang/otp自带的分布式数据库管理系统.mnesia配合erlang的实现近乎理想,但在实际使用当中差强人意,总会有一些不足.mnesia数据表没有主键自增的功能,但在mnesi ...
- 10款AJAX/CSS/HTML的在线表单生成器
本文转载:http://www.oschina.net/news/24327/10-ajax-css-html-online-form-builder 在这篇文章中,我们将介绍10个超棒的在线表单生成 ...
- Windows7下32位IE异常不能打开解决方法
今天更新了Update及安装了一些软件,重启电脑后发现32位IE不能正常打开,而64位IE正常. 错误信息如下: 问题签名: 问题事件名称: BEX 应用程序名: iexplore.exe 应用 ...
- [资源分享]神州数码 思科 UCS 虚拟化培训资料
神州数码 思科 UCS 虚拟化培训资料 点击文件名下载 UCS统一计算平台=.pdf 云计算Demo实验教材_Nexus 5K2K实验.pdf 云计算数据中心架构与技术.pdf 云计算数据中心虚拟 ...
- [Javascript] Log Levels and Semantic Methods
Go beyond console.log by learning about log levels, filtering log output and structuring your output ...