3403: [Usaco2009 Open]Cow Line 直线上的牛

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 48  Solved: 41
[Submit][Status]

Description

题目描述
    约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:
  .一只奶牛加入队伍的左边(输入“AL”).
  .一只奶牛加入队伍的右边(输入“AR”).
  ·K只队伍左边奶牛离开(输入“DLK”).
  ·K只队伍右边奶牛离开(输入“DRK”).
    请求出最后的队伍是什么样.
    数据保证离开的奶牛不会超过队伍里的奶牛数,最后的队伍不空

Input

    第1行输入S,之后S行每行描述一次事件,格式如题目描述所示

Output

 
    由左到右输出队伍最后的情况.

Sample Input

10
A L
A L
A R
A L
D R 2
A R
A R
D L 1
A L
A R

Sample Output

7
2
5
6
8

HINT

Source

题解:
呵呵,暴力均摊复杂度也是O(n)的
代码:(copy)
 #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 直线上的牛的更多相关文章

  1. BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )

    直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...

  2. 3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[S ...

  3. 【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3404 裸的双端队列.. #include <cstdio> #include <c ...

  4. B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque

    deque真的秀,queue和stack...没啥用了啊.操作差不多,就是在前面加一个front||back_就行了. 题干: 题目描述 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队 ...

  5. BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)

    直接双端队列模拟,完了= = CODE: #include<cstdio>#include<algorithm>#include<iostream>#include ...

  6. 149 Max Points on a Line 直线上最多的点数

    给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ Jav ...

  7. BZOJ3403:[USACO2009OPEN]Cow Line

    浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...

  8. [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. ...

  9. 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 ...

随机推荐

  1. 用endsWith()来限制图片的后缀名

    var a=document.getElementById('file-name'); var filename=a.value if(!a.endsWith('.jpg')||!a.endsWith ...

  2. ASP.NET页面同时发起多个ajax请求,出现阻塞情况

    解决办法:假如页面对Session只读不写,可以在页面的开头加上EnableSessionState="ReadOnly".

  3. Android ExpandableListView BaseExpandableListAdapter (类似QQ分组列表)

    分组列表视图(ExpandableListView) 和ListView不同的是它是一个两级的滚动列表视图,每一个组可以展开,显示一些子项,类似于QQ列表,这些项目来至于ExpandableListA ...

  4. atitit.提升研发效率的利器---重型框架与类库的差别与设计原则

    atitit.提升研发效率的利器---重型框架与类库的差别与设计原则 1. 框架的意义---设计的复用 1 1.1. 重型框架就是it界的重武器. 1 2. 框架 VS. 库 可视化图形化 1 2.1 ...

  5. 扩展欧几里德 POJ 1061

    欧几里德的是来求最大公约数的,扩展欧几里德,基于欧几里德实现了一种扩展,是用来在已知a, b求解一组x,y使得ax+by = Gcd(a, b) =d(解一定存在,根据数论中的相关定理,证明是用裴蜀定 ...

  6. json 项目应用

    package com.founder.ec.dec.action; import java.net.URLEncoder; import java.util.HashMap; import java ...

  7. VB中的Dictionary对象

    VB中的Dictionary对象 Dictionary对象不是VBA或Visual Basic实时语言的具体存在的部分,它是存在于Microsoft Scripting Runtime Library ...

  8. 解决:debug-stripped.ap_' specified for property 'resourceFile' does not exist.

    1.错误描述 更新Android Studio到2.0版本后,出现了编译失败的问题,我clean project然后重新编译还是出现抑郁的问题,问题具体描述如下所示: Error:A problem ...

  9. Ubuntu11.10与r8168网卡不兼容导致网络时断时续的问题

    安装了ubuntu11.10之后,感觉上网啥的很不稳定,ssh连接内网机器也是一条命令卡半天,检查了各方面的原因,网络没有什么问题,最后才发现是网卡驱动的问题,网上搜了一下是由于linux(ubunt ...

  10. 商务智能(BI)技术

    以下内容仅为兴趣爱好. 商务智能技术是将数据仓库.联机分析处理(OLAP)和数据挖掘等结合起来应用到商业活动中,从不同的数据源收集数据,经过抽取(Extract).转换(Transform)和加载(L ...