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 ...
随机推荐
- Unix C++(boost) 线程同步和线程组
#include <boost/thread.hpp> #include <iostream> #include <vector> #include <cst ...
- java中Class.forName与new
一.使用Class.forName 1.装载类 Class clazz = Class.forName("xx.xx.xx"); 2.初始化对象 clazz.newInstance ...
- CSS实现垂直居中的常用方法
在前端开发过程中,盒子居中是常常用到的.其中 ,居中又可以分为水平居中和垂直居中.水平居中是比较容易的,直接设置元素的margin: 0 auto就可以实现.但是垂直居中相对来说是比较复杂一些的.下面 ...
- Linux shell 脚本中”2>&1″的含义解释
脚本是:nohup /mnt/Nand3/H2000G >/dev/null 2>&1 & 对于& 1 更准确的说应该是文件描述符 1,而1 一般代表的就是 ...
- ORACLE复制数据库【weber出品】
一.概述 在公司中,我们会经常面临着一种情况.我们制定了对数据库的操作方案后,还不可以在真正的数据库上执行,需要在备用数据库进行测试,这个时候就需要备用数据上的数据和真正数据库的数据是一模一样的.我们 ...
- Lua 基础知识-面向对象
通过函数闭包的方式来实现面向对象 -- 通过函数闭包的方式来实现面向对象 function People(name) local self = {} local function init() sel ...
- Swift - 38 - 枚举的基本语法
//: Playground - noun: a place where people can play import UIKit // 创建一个枚举类型就相当于创建了一个新的数据类型, 所以首字母应 ...
- java学习——集合框架(Collection,List,Set)
集合类的由来: 对象用于封装特有数据,对象多了需要存储,如果对象的个数不确定,就使用集合容器进行存储. 集合特点:1,用于存储对象的容器.2,集合的长度是可变的.3,集合中不可以存储基本数据类型值. ...
- ubuntu自动挂载windows分区和开机自动启动wallproxy
1. 自动挂载windows分区 ubuntu默认是要点一下相应的盘符才会挂载windows分区的. 今天发现了ubuntu下最简单的自动挂载windows分区的办法.... :) 参考如下方法:ht ...
- Linux 从 sar 到 sar2html 的认识
这些变形的工具.诸如:淘宝的Tsar.ksar.sar2html....等.都是通过抓取 sar的数据 所以在最终呈现的数据上变化不大.只是展现的手段和效果不一样而已 sar 是帮助我们 ...