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性能分析命令和性能观察工具
- 菜鸟学习 - Unity中的热更新 - LuaInterface用户指南
[由于学习,所以翻译!] 1.介绍 LuaInterface 是 Lua 语言和 Microsoft.NET 平台公共语言运行时 (CLR) 之间的集成库. 非常多语言已经有面向 CLR 编译器和 C ...
- Spine(2D骨骼动画)
点击进入Spine官网 Spine 是一款针对游戏的 2D 骨骼动画编辑工具. Spine 旨在提供更高效和简洁 的工作流程,以创建游戏所需的动画. 功能: 1.摄影表 Dopesheet 在动画制作 ...
- 微信公众平台java开发具体解释(project代码+解析)
说明: 本次的教程主要是对微信公众平台开发人员模式的解说,网络上非常多类似文章,但非常多都让初学微信开发的人一头雾水,所以总结自己的微信开发经验,将微信开发的整个过程系统的列出,并对主要代码进行解说分 ...
- ubuntu下mysql中文乱码问题
本来就是想弄个网页往数据库里添加数据的,然后就发现了mysql的中文乱码问题,弄了半天解决方法如下: 首先停mysql服务,编辑配置文件my.cnf $ sudo stop mysql $sudo v ...
- 【转】iOS实时卡顿监控
转自http://www.tanhao.me/code/151113.html/ 在移动设备上开发软件,性能一直是我们最为关心的话题之一,我们作为程序员除了需要努力提高代码质量之外,及时发现和监控软件 ...
- (转 飛雲若雪)ADO.NET
一.简单介绍ADO.NET System.Data:DataTable,DataSet,DataRow,DataColumn,DataRelation,Constraint System.Data.C ...
- 学习日记-----ORM
ORM ORM(Object Relation Mapping)对象关系映射 实质:将数据库中 的业务数据用对象的形式表现出来,使用ORM在业务逻辑层和数据访问层之间充当桥梁 核心原则: 简单性 传达 ...
- SQL从入门到基础–03 SQLServer基础1(主键选择、数据插入、数据更新)
一.SQL语句入门 1. SQL语句是和DBMS“交谈”专用的语句,不同DBMS都认SQL语法. 2. SQL语句中字符串用单引号. 3. SQL语句中,对于SQL关键字大小写不敏感,对于字符串值大小 ...
- XFire构建服务端Service的两种方式
1.原声构建: 2.集成spring构建 http://blog.csdn.net/carefree31441/article/details/4000436XFire构建服务端Service的两种方 ...