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

直接用STL的的deque就好了...

----------------------------------------------------------------------

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<iostream>

#include<deque>

#define rep( i , n ) for( int i = 0 ; i < n ; i++ )

#define clr( x , c ) memset( x , c , sizeof( x ) )

using namespace std;

deque< int > Q;

int main() {

freopen( "test.in" , "r" , stdin );

int s , num = 0;

cin >> s;

rep( i , s ) {

char op , pos;

scanf( " %c %c" , &op , &pos );

if( op == ‘A‘ ) {

pos == ‘L‘ ? Q.push_front( ++num ) : Q.push_back( ++num );

} else {

int cnt;

scanf( "%d" , &cnt );

if( pos == ‘L‘ ) {

while( cnt-- ) Q.pop_front();

} else {

while( cnt-- ) Q.pop_back();

}

}

}

while( ! Q.empty() ) {

printf( "%d\n" , Q.front() );

Q.pop_front();

}

return 0;

}

----------------------------------------------------------------------

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

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 79  Solved: 70
[Submit][Status][Discuss]

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

Silver

时间: 2024-08-29 10:53:25

BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )的相关文章

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

3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[Submit][Status] Description 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一: .一只奶牛加入队伍的左边(输入“AL”). .一只奶牛加入队伍的右边(输入“AR

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

3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 41[Submit][Status] Description 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一: .一只奶牛加入队伍的左边(输入“AL”). .一只奶牛加入队伍的右边(输入“AR

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

给定二维平面上有 n 个点,求最多有多少点在同一条直线上. 详见:https://leetcode.com/problems/max-points-on-a-line/description/ /** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Point(int a, int b) : x(a), y(b) {} * }; */ class Solution {

BZOJ 1692 &amp;&amp; 1640 Best Cow Line 队列变换

Description FJ 打算带着他可爱的N (1 ≤ N ≤ 2,000)头奶牛去参加”年度最佳老农”的比赛.在比赛中,每个农夫把他的奶牛排成一列,然后准备经过评委检验. 比赛中简单地将奶牛的名字缩写为其头字母(the initial letter of every cow),举个例子,FJ带了Bessie, Sylvia,和Dora,那么就可以缩写为BSD. FJ只需将奶牛的一个序列重新排列,然后参加比赛.他可以让序列中的第一头奶牛,或者最后一头走出来,站到新队列的队尾. 利欲熏心的FJ

【BZOJ】【3301】【USACO2011 Feb】Cow Line

康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 序列->序号:(康托展开) 对于每个数a[i],数比它小的数有多少个在它之前没出现,记为b[i],$ans=1+\sum b[i]* (n-i)!$ 序号->序列:(逆康托展开) 求第x个排列所对应的序列,先将x-1,然后对于a[i],$\left\floor \frac{x}{(n-i)!} \right\floor $即为在它之后出现的比它小的数的个数,所以从小到大数一下有几个没出现的数,就知道a[

[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. Example 1: Input: [[1,1],[2,2],[3,3]] Output: 3 Explanation: ^ | |        o |     o |  o   +-------------> 0  1  2  3 4 Example 2: Input: [[1,1],[3,2]

Max Points on a Line(直线上最多的点数)

给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | |        o |     o |  o   +-------------> 0  1  2  3 4 示例 2: 输入: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] 输出: 4 解释: ^ | | o |     o   o |      o |  o   o +------------------

P2952 [USACO09OPEN]牛线Cow Line

题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, some number of cows on the left

BZOJ 1629: [Usaco2007 Demo]Cow Acrobats

Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a ca