deque真的秀,queue和stack。。。没啥用了啊。操作差不多,就是在前面加一个front||back_就行了。

题干:

题目描述

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

输入格式

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

输出格式

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

样例输入

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

样例输出

7
2
5
6
8

提示


题目来源

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<deque>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = 1e9 + ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
deque <int> de;
char s[];
int num = ;
int main()
{
int n;
read(n);
duke(i,,n)
{
scanf("%s",s);
if(s[] == 'A')
{
scanf("%s",s);
if(s[] == 'L')
de.push_front(++num);
else
de.push_back(++num);
}
else
{
int x;
scanf("%s",s);
read(x);
if(s[] == 'L')
{
while(x != )
{
// cout<<de.front()<<endl;
de.pop_front();
x--;
}
}
else
{
while(x != )
{
// cout<<de.back()<<endl;
de.pop_back();
x--;
}
}
}
}
while(!de.empty())
{
printf("%d\n",de.front());
de.pop_front();
}
return ;
}

B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque的更多相关文章

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

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

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

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

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

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

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

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

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

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

  9. lintcode 中等题:Max Points on a Line 最多有多少个点在一条直线上

    题目 最多有多少个点在一条直线上 给出二维平面上的n个点,求最多有多少点在同一条直线上. 样例 给出4个点:(1, 2), (3, 6), (0, 0), (1, 3). 一条直线上的点最多有3个. ...

随机推荐

  1. JS中for循环多个变量的判断原理

    看完下面两个例子的比较就明白了,其实就是逗号表达式,总是依据最后一个表达式的值. for(i=0, j=0; i<10, j<6; i++, j++){ k = i + j; consol ...

  2. 配置git使用ssh方式克隆gitlab的代码

    配置ssh key https://www.cnblogs.com/hafiz/p/8146324.html 配置host https://www.cnblogs.com/kaerxifa/p/109 ...

  3. ubuntu14.0开机guest账号禁用方法

    在终端里进入/usr/share/lightdm/lightdm.conf.d/目录 sudo vim 50-unity-greeter.conf 然后在文件里输入: [SeatDefaults] a ...

  4. 用shell编写dhcp自动获取脚本

    #!/bin/bash#net=$(ifconfig ens33 | awk -F'[ .]+' '/inet\>/{print $3"."$4"."$5 ...

  5. vue.js---利用vue cli脚手架工具+webpack创建项目遇到的坑

    1.Eslint js代码规范报错 WARNING Compiled with 2 warnings 10:43:26 ✘ http://eslint.org/docs/rules/quotes St ...

  6. python之urllib库

    urllib库 urllib库是Python中一个最基本的网络请求库.可以模拟浏览器的行为,向指定的服务器发送一个请求,并可以保存服务器返回的数据. urlopen函数: 在Python3的urlli ...

  7. 基于jquery的常见函数封装

    /// <reference path="jquery-1.8.0.min.js" />/** DIV或元素居中* @return*/jQuery.fn.mCenter ...

  8. 思维风暴 codeforces (1060A) Phone Numbers

    这个题我真是我的问题,我看到这种题直接就想着怎么用string去枚举破解,开了一个数组去做结果模拟失败,可能开个stl容器能做的好一点...但是这个题完全不是这样做的...实际上直接比较8的个数和合法 ...

  9. 熟悉RHEL7登录界面使用

    Linux操作系统提供了图像界面和字符界面两种操作环境. 图像界面: 1.开启RHEL7后进入到该界面,图中用户是我们创建的本地用户,如果我们要以管理员身份登录则点击Not listed(未列出). ...

  10. 读取json文件并把uft-8转换为ascii

    #!/usr/bin/python import sys import json as js import codecs import collections #reload(sys) #sys.se ...