11995 - I Can Guess the Data Structure!

Time limit: 1.000 seconds

Problem I

I Can Guess the Data Structure!

There is a bag-like data structure, supporting two operations:

1 x

Throw an element x into the bag.

2

Take out an element from the bag.

Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine!

Input

There are several test cases. Each test case begins with a line containing a single integer n (1<=n<=1000). Each of the next n lines is either a type-1 command, or an integer 2 followed by an integer x. That means after executing a type-2 command, we get an element x without error. The value of x is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF). The size of input file does not exceed 1MB.

Output

For each test case, output one of the following:

stack

It's definitely a stack.

queue

It's definitely a queue.

priority queue

It's definitely a priority queue.

impossible

It can't be a stack, a queue or a priority queue.

not sure

It can be more than one of the three data structures mentioned above.

Sample Input

6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4

Output for the Sample Input

queue
not sure
impossible
stack
priority queue

Rujia Liu's Present 3: A Data Structure Contest Celebrating the 100th Anniversary of Tsinghua University
Special Thanks: Yiming Li
Note: Please make sure to test your program with the gift I/O files before submitting!

题解:STL中 queue、stack、priority_queue的使用。

代码:

 #include<cstdio>
#include<cstring>
#include<stdbool.h>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm> #define rep(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x)) using namespace std; int i,j,x,y,pri,qui,sti; void check()
{
if(qui== && pri== && sti==) printf("queue\n");
else
if(qui== && pri== && sti==) printf("priority queue\n");
else
if(qui== && pri== && sti==) printf("stack\n");
else
if(qui== && pri== && sti==) printf("impossible\n");
else
printf("not sure\n");
} int main()
{
int T; while(scanf("%d",&T)!=EOF) {
pri=qui=sti=; queue <int> Q;
stack <int> S;
priority_queue <int> prQ; while(T--) {
scanf("%d%d",&x,&y);
if(x==) {
Q.push(y);
S.push(y);
prQ.push(y);
}
else { if(qui==) {
if(Q.empty() || Q.front()!=y) qui=;
if(!Q.empty()) Q.pop();
} if(sti==) {
if(S.empty() || S.top()!=y) sti=;
if(!S.empty()) S.pop();
} if(pri==) {
if(prQ.empty() || prQ.top()!=y) pri=;
if(!prQ.empty()) prQ.pop();
}
}
} check();
} return ;
}

[UVA] 11995 - I Can Guess the Data Structure! [STL应用]的更多相关文章

  1. UVA - 11995 - I Can Guess the Data Structure! STL 模拟

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

  2. UVa 11995:I Can Guess the Data Structure!(数据结构练习)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  3. UVA 11995 I Can Guess the Data Structure!(ADT)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  4. STL UVA 11995 I Can Guess the Data Structure!

    题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...

  5. UVa 11995 I Can Guess the Data Structure!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

  6. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  7. UVA - 11995 I Can Guess the Data Structure!(模拟)

    思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...

  8. uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)

    11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...

  9. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

随机推荐

  1. C++类的数组元素查找最大值问题

    找出一个整型数组中的元素的最大值. /*找出一个整型数组中的元素的最大值.*/ #include <iostream> using namespace std; class ArrayMa ...

  2. TestNG使用Eclipse建立Test Case - 就是爱Java

    除了JUnit可以进行单元测试外,还可以使用TestNG来撰写Test Case,这是另一种测试Framework,它是为更广泛的测试场合而设计,可以运行在没有修改过的JUnit测试,除非看到它们的i ...

  3. 绝美Sysinternals

    啥也不说了,自己看吧: https://technet.microsoft.com/en-us/sysinternals/bb545046 新地址: https://technet.microsoft ...

  4. BZOJ2101: [Usaco2010 Dec]Treasure Chest 藏宝箱

    2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 327  Solved:  ...

  5. MVC4.0系统开发新手历程(一)

    接手了一个简单的销售奖金计算的项目,虽然不算大但是业务逻辑比较复杂,还夹杂了很多的特殊情况,毕竟是大公司什么样的人都有,好了不多说切入正题,项目是公司的一个前辈负责的,在他做系统架构的时候让我们了解下 ...

  6. bootstrap学习以及其插件

    Bootstrap中文网地址,里面有bootstrap组件的下载与使用说明,现在使用bootstrap3: http://www.bootcss.com/ W3CSchool.CC里面有学习boots ...

  7. Pojo和JavaBean的区别(转载)

    OJO(Plain Old Java Object)这个名字用来强调它是一个普通java对象,而不是一个特殊的对象. 2005年11月时,“POJO”主要用来指代那些没用遵从特定的Java对象模型,约 ...

  8. C# XML 根级别上的数据无效

    XmlDocument加载xml方法 XmlDocument doc = new XmlDocument(); //加载xml 字符串 doc.LoadXml(_Store); //加载xml文件 d ...

  9. myeclipse添加svn

    一直在用MyEclipse,每次重装或者换开发环境时都需要安装svn插件,每次都是在网上找,感觉没有说的太明白的,还是自己写个以备将来查看. 安装svn插件有很多种方式,在线的.离线的.解压的(又分为 ...

  10. Oracle异常的抛出处理

    --一异常处理的代码 --sqlcode 异常编号 --sqlerrm 信号字符串 /* 在plsql 块中格式 Declare 变量 Begin 代码块 EXCEPTION when 异常的名称 t ...