【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404
裸的双端队列。。
#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=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; 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=100005;
int q[N], n, front, tail; inline void fix(int &x) { if(x<0) x=N+x; if(x>=N) x-=N; }
int main() {
read(n);
int cnt=0;
for1(i, 1, 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 0;
}
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
【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)的更多相关文章
- BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...
- BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)
直接双端队列模拟,完了= = CODE: #include<cstdio>#include<algorithm>#include<iostream>#include ...
- 3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 71 Solved: 62[S ...
- BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 48 Solved: 41[S ...
- B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque
deque真的秀,queue和stack...没啥用了啊.操作差不多,就是在前面加一个front||back_就行了. 题干: 题目描述 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队 ...
- 149 Max Points on a Line 直线上最多的点数
给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...
随机推荐
- PageRank学习
喜欢手写学习,记忆深刻(字丑勿喷!). 计算过程的代码如下: public class PageRank { private static double m[][]={ { 0 , 0.5 , 1 , ...
- selenium获取html源代码
# 执行js得到整个HTML html = driver.execute_script("return document.documentElement.outerHTML") 获 ...
- 搭建Vue环境总是出错,就重新安装就好了
总是报错,还不如重新安装.. 错误千奇百怪,解决了 这个错误又会出现另外一个. 百度了一个挺好用的e 在window下搭建Vue.Js开发环境 nodejs官网http://nodejs.cn/下 ...
- TP框架中模板赋值
TP框架中模板赋值 $this->assign('name',$value); $this->name = $value; // 两种写法是等效的
- docker高级应用之cpu与内存资源限制(转)
时间:2015-06-09 14:01:52 阅读:1581 评论:0 收藏:0 [点我收藏+] 标签:docker资源限制 docker cpu限制 ...
- ORA-01400: 无法将 NULL 插入 ("CHARGE_WQRL"."SF_JMQTFY_T"."BH")
[ERROR] JmCheckManageDaoImpl:901 - java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("CHARGE_WQRL& ...
- Sphinx-实战
配置完成后, 有了数据源.索引文件存储位置等, 便可以使用 indexer 工具创建索引, 收集要被检索的数据 -c 指定配置文件 默认使用 etc/sphinx.conf --all 对所有索引重新 ...
- R快速创建个文件
cat("TITLE extra line", "2 3 5 7", "11 13 17", file="ex.data" ...
- poj_2773
题目的愿意非常easy.给你一个n,求在升序排列的情况下,第k个与之相互素的数. 解法:首先我们要知道gcd(b×t+a,b)=gcd(a.b),那么接下来就非常easy了.全部与之互素的数都是以ph ...
- Team Foundation Server安装指南(转载)
1.说明 Team Foundation Server(以下简称VSTF)的安装并不是一件轻松的事情,在安装的过程中相信很多人都或多或少碰到一些问题而安装不成功,虽然手头有微软提供的所谓安装手册,也曾 ...