洛谷——P2952 [USACO09OPEN]牛线Cow Line
P2952 [USACO09OPEN]牛线Cow Line
题目描述
Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, some number of cows on the left or right side of the line all leave the line to go graze in their favorite pasture.
FJ has trouble keeping track of all the cows in the line. Please help him.
The cows enter the line in numerical order 1..N, and once a cow leaves the line she never re-enters it. Your program will be given S (1 <= S <= 100,000) input specifications; each appears on a single line and is one of two types:
A cow enters the line (a parameter indicates whether on the left or right).
- K cows leave the line from the left or right side (supplied parameters define both the number of cows and which side).
Input lines never request an operation that can not be performed.
After all the input lines have been processed, your program should print the cows in the line in order from left to right. The final line is guaranteed to be non-empty at the end of the input
specifications.
约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:
.一只奶牛加入队伍的左边(输入“AL”).
.一只奶牛加入队伍的右边(输入“AR”).
·K只队伍左边奶牛离开(输入“DLK”).
·K只队伍右边奶牛离开(输入“DRK”).
请求出最后的队伍是什么样.
数据保证离开的奶牛不会超过队伍里的奶牛数,最后的队伍不空
输入输出格式
输入格式:
Line 1: A single integer: S
Lines 2..S+1: Line i+1 contains specification i in one of four formats:
A L -- a cow arrives on the Left of the line
A R -- a cow arrives on the Right of the line
D L K -- K cows depart the Left side of the line
- D R K -- K cows depart the Right side of the line
第1行输入S,之后S行每行描述一次事件,格式如题目描述所示
输出格式:
- Lines 1..??: Print the numbers of the cows in the line in order from left to right, one number per line.
由左到右输出队伍最后的情况.
输入输出样例
说明
Input Resulting Cow Line
A L 1
A L 2 1
A R 2 1 3
A L 4 2 1 3
D R 2 4 2
A R 4 2 5
A R 4 2 5 6
D L 1 2 5 6
A L 7 2 5 6
A R 7 2 5 6 8
感谢@ ws_fuweidong 提供翻译。
双端对列
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char ch;
deque<int>q;
int n,k,s,ans;
int read()
{
,f=; char ch=getchar();
;ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
int main()
{
n=read();
;i<=n;i++)
{
cin>>ch;
if(ch=='A')
{
s++;
cin>>ch;
if(ch=='L')
q.push_front(s);
else
q.push_back(s);
}
else
{
cin>>ch;k=read();
if(ch=='L')
;i<=k;i++)
q.pop_front();
else
;i<=k;i++)
q.pop_back();
}
}
while(!q.empty())
{
ans=q.front();
q.pop_front();
printf("%d\n",ans);
}
;
}
洛谷——P2952 [USACO09OPEN]牛线Cow Line的更多相关文章
- 洛谷 P3014 [USACO11FEB]牛线Cow Line
P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) ...
- [洛谷P3014][USACO11FEB]牛线Cow Line (康托展开)(数论)
如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里: 简陋的博客 百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行 ...
- 洛谷:P2952 [USACO09OPEN]牛线Cow Line:题解
题目链接:https://www.luogu.org/problemnew/show/P2952 分析: 这道题非常适合练习deque双端队列,~~既然是是练习的板子题了,建议大家还是练练deque, ...
- 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...
- P3014 [USACO11FEB]牛线Cow Line && 康托展开
康托展开 康托展开为全排列到一个自然数的映射, 空间压缩效率很高. 简单来说, 康托展开就是一个全排列在所有此序列全排列字典序中的第 \(k\) 大, 这个 \(k\) 即是次全排列的康托展开. 康托 ...
- 洛谷P3045 [USACO12FEB]牛券Cow Coupons
P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB ...
- 洛谷P2950 [USACO09OPEN]牛绣Bovine Embroidery
P2950 [USACO09OPEN]牛绣Bovine Embroidery 题目描述 Bessie has taken up the detailed art of bovine embroider ...
- 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...
- 洛谷P2901 [USACO08MAR]牛慢跑Cow Jogging
题目描述 Bessie has taken heed of the evils of sloth and has decided to get fit by jogging from the barn ...
随机推荐
- redis.conf详细说明
daemonize yes #---默认值no,该参数用于定制redis服务是否以守护模式运行.--- pidfile /var/run/redis.pid #默认值/var/run/redis.pi ...
- Centos 6 FTP 配置
How to configure ftp server on centos 6 Posted krizna Centos FTP – File transfer protocol is used ...
- 要back的题目 先立一个flag
要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...
- 【CodeForces】835D Palindromic characteristics
[题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...
- 【BZOJ】1724 [Usaco2006 Nov]Fence Repair 切割木板
[算法]贪心+堆 #include<cstdio> #include<algorithm> using namespace std; ; int n,heap[maxn],sz ...
- 如何设计一个优雅健壮的Android WebView?(上)
转:如何设计一个优雅健壮的Android WebView?(上) 前言 Android应用层的开发有几大模块,其中WebView是最重要的模块之一.网上能够搜索到的WebView资料可谓寥寥,Gith ...
- node起本地服务器以及实现代理,前端接口转发
上一篇文章写了使用docker来做nginx镜像实现本地的页面代理以及接口转发,但是需要下载docker,这个对于很多人来说还是显得比较麻烦,于是这个文章就是介绍如何只用node就可以代理本地的页面和 ...
- 25、如何实现redis集群?
由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...
- 获取应用版本号,版本名称,包名,AppName,图标,是否是系统应用,获取手机中所有应用,所有进程
PackageManager packageManager = getPackageManager(); PackageInfo packageInfo; = packageManager.getPa ...
- Java多线程学习(二)synchronized关键字(1)
转载请备注地址: https://blog.csdn.net/qq_34337272/article/details/79655194 Java多线程学习(二)将分为两篇文章介绍synchronize ...