题解 CF546C 【Soldier and Cards】
思路
是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素!
代码
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn=+;
int main()
{
int n;
cin>>n;
queue<int>a;//队列
queue<int>b;
int x,y;
cin>>x;
for(int i=;i<x;i++)
{
int x;
cin>>x;
a.push(x);
}
cin>>y;
for(int i=;i<y;i++)
{
int y;
cin>>y;
b.push(y);
}
int sum=;//记录步数
bool flag=;//判断输赢以及游戏是否结束
while(sum<=maxn)
{
int u=a.front();a.pop();
int v=b.front();b.pop();
sum++;
if(u>v)
{
a.push(v);//U比V大时
a.push(u);
}
else
{
b.push(u);//U比V小时
b.push(v);
}
if(a.size()==&&b.size()==)//游戏结束
break;
if(a.size()==)
{
printf("%d %d\n",sum,);
flag=;
}
if(b.size()==)
{
printf("%d %d\n",sum,);
flag=;
}
if(flag==)break;
}
if(flag==)printf("-1\n");
return ;
}
是不是很简单呢?
题解 CF546C 【Soldier and Cards】的更多相关文章
- [CF546C] Soldier and Cards - 模拟
两个人玩牌,首先两个人都拿出自己手牌的最上面的进行拼点,两张拼点牌将都给拼点赢得人,这两张牌放入手牌的顺序是:先放对方的牌再放自己的.若最后有一个人没有手牌了,那么他就输了,求输出拼点的次数和赢得人的 ...
- 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 ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- 【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 ...
- CF Soldier and Cards (模拟)
Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- 【CodeForces - 546C】Soldier and Cards (vector或队列)
Soldier and Cards 老样子,直接上国语吧 Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌, ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
随机推荐
- Rand工具类
这篇文章已经废弃. 实际开发中,这个工具类用到得非常少. RandN是主要类,用于生成指定位数的随机字符串,具体功能在这个类中实现 Rand8是修饰了RandN中每个对外方法的修饰类,用与生成8位的随 ...
- WPF中,Grid与Table的区别(英文)-转载
原文地址:http://blog.csdn.net/johnsuna/article/details/1742799 How is Grid Different from Table?Table an ...
- 两大主流开源分布式存储的对比:GlusterFS vs. Ceph
两大主流开源分布式存储的对比:GlusterFS vs. Ceph 存储世界最近发生了很大变化.十年前,光纤通道SAN管理器是企业存储的绝对标准,但现在的存储必须足够敏捷,才能适应在新的基础架构即服务 ...
- struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []
使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...
- Ubuntu18.04上安装N卡驱动、CUDA、CUDNN三连
环境:Ubuntu18.04 显卡驱动真的挺方便的,CUDA和CUDNN还是踩了一些坑2333 1.安装显卡驱动 安装ubuntu更新或sudo apt-get update & sudo a ...
- FreeMarker学习(springmvc配置)
springMvc配置 <bean id="freemarkerConfig" class="org.springframework.web.servlet.vie ...
- arcgis python 删除一个数据库所有数据
# -*- coding: cp936 -*- import xlrd # must init xlrd import arcpy import os def main(): arcpy.env.wo ...
- 《maven实战》笔记(2)----一个简单maven项目的搭建,测试和打包
参照<maven实战>在本地创建对应的基本项目helloworld,在本地完成后项目结构如下: 可以看到maven项目的骨架:src/main/java(javaz主代码)src/test ...
- LC 985. Sum of Even Numbers After Queries
We have an array A of integers, and an array queries of queries. For the i-th query val = queries[i] ...
- js for (i=0;i<a.length;a[i++]=0) 中等于0怎么理解?
js的问题for (i=0;i<a.length;a[i++]=0) 中等于0怎么理解? 很奇怪的一个for循环 竟然是将原来数组的数据全改为0