BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 48 Solved: 41
[Submit][Status]
Description
Input
Output
Sample Input
A L
A L
A R
A L
D R 2
A R
A R
D L 1
A L
A R
Sample Output
2
5
6
8
HINT
Source
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=, k=; char c=getchar(); for(; c<''||c>''; c=getchar()) if(c=='-') k=-; for(; c>=''&&c<=''; c=getchar()) r=r*+c-''; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=;
int q[N], n, front, tail; inline void fix(int &x) { if(x<) x=N+x; if(x>=N) x-=N; }
int main() {
read(n);
int cnt=;
for1(i, , n) {
char ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
if(ch=='A') {
ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
if(ch=='L') { --front; fix(front); q[front]=++cnt; }
else if(ch=='R') q[tail++]=++cnt, fix(tail);
}
else if(ch=='D') {
ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
int t=getint();
if(ch=='L') front+=t, fix(front);
else if(ch=='R') tail-=t, fix(tail);
}
}
while(front!=tail) {
printf("%d\n", q[front++]); fix(front);
}
return ;
}
BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛的更多相关文章
- BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...
- 3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 71 Solved: 62[S ...
- 【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 裸的双端队列.. #include <cstdio> #include <c ...
- B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque
deque真的秀,queue和stack...没啥用了啊.操作差不多,就是在前面加一个front||back_就行了. 题干: 题目描述 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队 ...
- BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)
直接双端队列模拟,完了= = CODE: #include<cstdio>#include<algorithm>#include<iostream>#include ...
- 149 Max Points on a Line 直线上最多的点数
给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...
- BZOJ3403:[USACO2009OPEN]Cow Line
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
- [Swift]LeetCode149. 直线上最多的点数 | Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- LeetCode:149_Max Points on a line | 寻找一条直线上最多点的数量 | Hard
题目:Max Points on a line Given n points on a 2D plane, find the maximum number of points that lie on ...
随机推荐
- 二、linux文件系统之linux启动
Linux组成 kernel shell 文件系统 application(应用程序) 标准库函数 内核源码位置: /usr/src /boot/vmlinuz*(内核压缩文件,启动要加载) ...
- Android Studio 2.1.x 关联SDK API Source
问题: 看图=>,当在android studio里ctrl+鼠标左键查看例如: TextUtils.isEmpty(content);这段代码的isEmpty方法的实现的时候经常就跑到如图所示 ...
- Android Framework 记录之二
接着上次的记录,续写. 23.services文件夹 文件 描写叙述 class AlarmManagerService extends IAlarmManager.Stub { //定时管理服务 p ...
- JDKSDK配置
变量名:ANDROID_HOME 变量值: E:\android-sdk_r11-windows\android-sdk_r11-windowsclsspath .;%JAVA_HOME%\l ...
- Bottle 中文文档
译者: smallfish (smallfish.xy@gmail.com) 更新日期: 2009-09-25 原文地址: http://bottle.paws.de/page/docs (已失效) ...
- diameter - degree problem
如今要构建一个网络模型,网络中的每一个节点最多和 d 个节点相连接, 且信息的传播从随意一个节点到另外随意一个节点的"最短路径" (路径依照单位路径算)都不能超过 k,问网络中最多 ...
- 多表关联查询(ORACLE版)
前言:这几天学习oracle,把自己对于关联查询的理解,记录下.如有错误请指正! 交叉连接: 交欢连接又称为“笛卡儿积连接”,是两个或多个表之间的无条件连接.一个表中所有的记录与其它表的所有的记录进行 ...
- [转] 深入剖析 linux GCC 4.4 的 STL string
本文通过研究STL源码来剖析C++中标准模板块库std::string运行机理,重点研究了其中的引用计数和Copy-On-Write技术. 平台:x86_64-redhat-linux gcc ver ...
- [转] JSON for java入门总结
一.JSON介绍 JSON(JavaScript Object Notation),类似于XML,是一种数据交换格式,比如JAVA产生了一个数据想要给JavaScript,则除了利用XML外,还可以利 ...
- .NET简单的语句
获取当前时间的代码: Response.Write(DateTime.Now); 第一次加载页面的语句: if (!IsPostBack) { Response.Write("这是第一次加载 ...