11995 - 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).
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
Sample Output
queue
not sure
impossible
stack
priority queue

题意:水。。。

代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<queue>
  7. #include<vector>
  8. #include<stack>
  9. using namespace std;
  10. const int INF=0x3f3f3f3f;
  11. #define mem(x,y) memset(x,y,sizeof(x))
  12. #define SI(x) scanf("%d",&x)
  13. #define SL(x) scanf("%lld",&x)
  14. #define PI(x) printf("%d",x)
  15. #define PL(x) printf("%lld",x)
  16. #define P_ printf(" ")
  17. #define T_T while(T--)
  18. #define F(i,s,x) for(i=s;i<x;i++)
  19. const double PI=acos(-1.0);
  20. typedef long long LL;
  21. int main(){
  22. int n;
  23. while(~SI(n)){
  24. int x,t;
  25. queue<int>q;
  26. priority_queue<int>sq;
  27. stack<int>S;
  28. int a=1,b=1,c=1;
  29. int temp=0;
  30. while(n--){
  31. SI(t);SI(x);
  32. if(temp)continue;
  33. if(t==1){
  34. q.push(x);
  35. sq.push(x);
  36. S.push(x);
  37. }
  38. else{
  39. if(q.empty())temp=1;
  40. if(temp)continue;
  41. if(q.front()!=x)a=0;
  42. if(sq.top()!=x)b=0;
  43. if(S.top()!=x)c=0;
  44. q.pop();
  45. sq.pop();
  46. S.pop();
  47. }
  48. }
  49. if(temp||(a+b+c==0))puts("impossible");
  50. else if(a+b+c>1)puts("not sure");
  51. else if(a)puts("queue");
  52. else if(b)puts("priority queue");
  53. else if(c)puts("stack");
  54. }
  55. return 0;
  56. }

  

uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)的更多相关文章

  1. [UVA] 11995 - I Can Guess the Data Structure! [STL应用]

    11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Str ...

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

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

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

  6. UVa 11995 I Can Guess the Data Structure!

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

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

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

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

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

  9. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

随机推荐

  1. ASP.NET性能监视参数详解

    性能监视器- Performance Monitor 性能监视器是Windows自带的系统资源和性能监视工具. 性能监视器能够量化地提供CPU使用率, 内存分配状况, 异常派发情况, 线程调度频率等信 ...

  2. Problem B The Blocks Problem(vector的使用)

    题目链接:Problem B 题意:有n块木块,编号为0~n-1,要求模拟以下4种操作(下面的a和b都是木块编号) 1. move a onto b: 把a和b上方的木块全部归位,然后把a摞在b上面. ...

  3. Stack trace对性能的影响

    package ceshi; public class ExceptionTest { public long maxLevel = 20; public static void main(Strin ...

  4. GraphLab:新的面向机器学习的并行框架

    大规模图数据计算引起了许多知名公司的关注,微软提出了用于图数据匹配的Horton - Querying Large Distributed Graphs(Link:http://research.mi ...

  5. html常用标签有哪些

    html看似复杂,其实常用的标签并不多,这里总共介绍一些html的常用标签 文字处理: ①标题:<h1> to <h6> ②段落:<p>文字段落</p> ...

  6. nodejs的npm安装模块时候报错:npm ERR! Error: CERT_NOT_YET_VALID的解决方法 - 包子博客 _ 关注互联网前端、开发、SEO、移动互联网应用技术

    转载:包子博客: http://www.haodewap.net/visit.do?wapurl=http%3A%2F%2Fwww.jincon.com%2Farchives%2F141%2F

  7. 【双模卡的相关知识】解SIM卡前需要知道的信息(SIM年分和厂商识别)

    <ignore_js_op> 二.SIM版本问题SIM卡的版本有两种说法,一是有些是制造厂制定的,二是电信公司的制定.下面以移动为例,目前我们手里的SIM有几种版本:v0.v1.v2.v3 ...

  8. Google日历添加农历、节日和天气插件(步骤)

    Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...

  9. Android开发中怎样调用系统Email发送邮件(多种调用方式)

    在Android中调用其他程序进行相关处理,几乎都是使用的Intent,所以,Email也不例外,所谓的调用Email,只是说Email可以接收Intent并做这些事情 我们都知道,在Android中 ...

  10. installation - How to install Synaptic Package Manager? - Ask Ubuntu

    installation - How to install Synaptic Package Manager? - Ask Ubuntu How to install Synaptic Package ...