http://www.lydsy.com/JudgeOnline/problem.php?id=3404

裸的双端队列。。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. #define rep(i, n) for(int i=0; i<(n); ++i)
  10. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  11. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  12. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  13. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  14. #define CC(i,a) memset(i,a,sizeof(i))
  15. #define read(a) a=getint()
  16. #define print(a) printf("%d", a)
  17. #define dbg(x) cout << #x << " = " << x << endl
  18. #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
  19. 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; }
  20. inline const int max(const int &a, const int &b) { return a>b?a:b; }
  21. inline const int min(const int &a, const int &b) { return a<b?a:b; }
  22.  
  23. const int N=100005;
  24. int q[N], n, front, tail;
  25.  
  26. inline void fix(int &x) { if(x<0) x=N+x; if(x>=N) x-=N; }
  27. int main() {
  28. read(n);
  29. int cnt=0;
  30. for1(i, 1, n) {
  31. char ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
  32. if(ch=='A') {
  33. ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
  34. if(ch=='L') { --front; fix(front); q[front]=++cnt; }
  35. else if(ch=='R') q[tail++]=++cnt, fix(tail);
  36. }
  37. else if(ch=='D') {
  38. ch=getchar(); while(ch<'A'||ch>'Z') ch=getchar();
  39. int t=getint();
  40. if(ch=='L') front+=t, fix(front);
  41. else if(ch=='R') tail-=t, fix(tail);
  42. }
  43. }
  44. while(front!=tail) {
  45. printf("%d\n", q[front++]); fix(front);
  46. }
  47. return 0;
  48. }

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

【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)的更多相关文章

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

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

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

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

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

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

  4. BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛

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

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

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

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

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

  7. BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...

  8. BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...

  9. BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)

    一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...

随机推荐

  1. Hibernate关系映射(三) 多对一和一对多

    一.多对一 学生Student和班级Grade实现多对一,多个学生对应一个班级. Student.java实体类,映射了班级的属性. package com.lxit.entity; import j ...

  2. ES6 for...of循环

    1.for of const arr = ['red', 'green', 'blue']; for(let v of arr) { console.log(v); // red green blue ...

  3. XML Schema学习札记(1)——基础总览

    内容整理自:www.w3school.com.cn 转载自:http://www.xgezhang.com/xml_schema_1.html 什么是XML Schema? XML Schema 是基 ...

  4. mac 查看目前哪些进程占用哪些端口

    lsof -nP  | grep TCP | grep LISTEN lsof -i :TCP

  5. ECMAScript 6 | 新特性

    新特性概览 参考文章: http://www.cnblogs.com/Wayou/p/es6_new_features.html ——————————————————————————————————— ...

  6. Mybatis 插入后返回数据库自动增长ID

    MySQL和MSSQL返回主键方法 在personMap.xml中 <insert id="addPerson" parameterType="orm.Person ...

  7. excel合并单元格

    最简单的: =A1&B1&C1 在C14单元格中输入公式:=CONCATENATE(A14,"@",B14,".com"),确认后,即可将A14 ...

  8. Mac OS 下安装mysql环境

    传送门:Mac下安装与配置MySQL   mac 上怎么重置mysql的root的密码? 一.下载mysql 进入官方下载地址:https://www.mysql.com/downloads/ 1.找 ...

  9. PHP扩展开发及内核应用(未完)

    转: https://github.com/walu/phpbook

  10. atitit.系统架构图 的设计 与工具 attilax总结

    atitit.系统架构图 的设计 与工具 attilax总结 1. 架构图的4个版式(标准,(左右)悬挂1 2. 架构图的层次结构(下属,同事,助手)1 3. wps ppt1 4. 使用EDraw画 ...