Soldier and Cards

老样子,直接上国语吧

 Descriptions:

两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌,放在自己手牌的最下方,而且对方输掉的那张手牌需要放在上面,自己赢的手牌放在下面。

Input

第一行的数n代表一共有几张牌

第二行第一个数x代表第一个人有x张牌

第三行第一个数y代表第二个人有y张牌

Output

第一个数代表进行了几轮,第二个数代表谁赢

Examples

Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1

题目链接:

https://vjudge.net/problem/CodeForces-546C

我的做法可能有点偏了,因为不知道有几个牌,就用vector存一下,然后每次拿出双方的第一张牌进行比较,再进行模拟,现在想想可以用queue来写,当时写的有点粗糙,但是思路很清晰,一遍就AC了

AC代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
vector<int>a;
vector<int>b;
int n;
int f,flag=;
int x,y;
int sum=;
int main()
{
cin >> n;
cin >> x;
for(int i=; i<x; i++)
{
int num;
cin>>num;
a.push_back(num);
}
cin>>y;
for(int i=; i<y; i++)
{
int num;
cin>> num;
b.push_back(num);
}
while(!a.empty()&&!b.empty())//两人的卡牌都不为空
{
sum++;
int num1=a.front();//都取出第一张卡牌进行比较
int num2=b.front();
if(num1>num2)//1号大于2号就把2号和自己的卡牌一次放在队尾
{
a.push_back(num2);
a.push_back(num1);
vector<int>::iterator t1=a.begin();
vector<int>::iterator t2=b.begin();
a.erase(t1);
b.erase(t2);
}
if(num2>num1)//2号大于1号就把1号和自己的卡牌一次放在队尾
{
b.push_back(num1);
b.push_back(num2);
vector<int>::iterator t1=a.begin();
vector<int>::iterator t2=b.begin();
a.erase(t1);
b.erase(t2);
}
if(!b.empty())//谁的卡牌为空谁就输了
f=;
if(!a.empty())
f=;
if(sum>=n*n*n*n*n*n)//判断一下,要是循环这么多次还没分出胜负,应该就是死循环了
{
flag=;
cout<<"-1"<<endl;
break;
}
}
if(flag)
cout<<sum<<" "<<f<<endl;
return ;
}

【CodeForces - 546C】Soldier and Cards (vector或队列)的更多相关文章

  1. cf 546C Soldier and Cards

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

  2. 546C. Soldier and Cards

    题目链接 题意 两个人玩扑克,共n张牌,第一个人k1张,第二个人k2张 给定输入的牌的顺序就是出牌的顺序 每次分别比较两个人牌的第一张,牌上面数字大的赢,把这两张牌给赢的人,并且大的牌放在这个人的牌最 ...

  3. CodeForces 546C(队列)

    CodeForces 546C Soldier and Cards Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  4. 【codeforces 546C】Soldier and Cards

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

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

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

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

  7. 队列 Soldier and Cards

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

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

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

  9. CF Soldier and Cards (模拟)

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

随机推荐

  1. 走入asp.net mvc不归路:[3]创建控制器

    实际上,控制器就是一个类,一个继承自Controller的类.正常创建一个Controller即可,而问题在于asp.net mvc提供了一套便捷的方法,在创建一个Controller时,可以自动创建 ...

  2. unknownhostexception错误解决方案

    关于java.net.UnknownHostException大家也许都比较熟悉,今天我来整理一下关于java.net.UnknownHostException的各种处理办法: 1.在Android项 ...

  3. 【Mongodb教程 第十九课 】PHP与MONGODB的条件查询

    与普通的关系型数据库类似,在对数据的删.改.查的时候,会用到查询条件,如mysql中的 where… 而MongoDB中,经过php来做的所有的操作指令都是用array来包裹的: MongoColle ...

  4. 运营或生态链没做好,APP质量再高有个鸟用(下)

    上篇文章已经阐述了对于一款产品卖不卖作,事实上非常依赖于运营的打造和生态链的建立,这里能够解释为什么很多优秀的游戏产品功底非常好,但開始并不卖作,仅仅有碰到一家肯出力推的渠道游戏才迅速火了起来.这是不 ...

  5. 诊断并解决 ORA-4030 错误 (Doc ID 1548826.1)

    适用于: Oracle Database - Enterprise Edition - 版本号 8.1.7.4 和更高版本号 本文档所含信息适用于全部平台 用途 怎样诊断 ORA-4030 错误 排错 ...

  6. linux中select网络通信

    //ser.cpp #include <iostream> #include <fcntl.h> #include <sys/socket.h> #include ...

  7. Chrome浏览器V43版本号不支持silverlight 5.0的解决的方法

    场景: 浏览器:chrome V43 插件:silverlight 5.0 操作系统:xp 问题: 自己开发silverlight站点在IE7和firefox中能正常打开,但在chrome中打开失败. ...

  8. gRPC错误码 http状态码 provide your APIs in both gRPC and RESTful style at the same time

    How gRPC error codes map to HTTP status codes in the response https://github.com/grpc-ecosystem/grpc ...

  9. ABAP debug遇到问题

    新项目的系统,调试是老出现这个框不断弹出,一堆出来 都来不及关. 不确定是不是因为可用对话框不够的原因.

  10. Hadoop中序列化与Writable接口

    学习笔记,整理自<Hadoop权威指南 第3版> 一.序列化 序列化:序列化是将 内存 中的结构化数据 转化为 能在网络上传输 或 磁盘中进行永久保存的二进制流的过程:反序列化:序列化的逆 ...