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. asp.net 管道模型+生命处理周期

    http://www.cnblogs.com/qianlifeng/archive/2010/12/16/1908568.html https://msdn.microsoft.com/zh-cn/l ...

  2. android开发论坛

    http://www.hiapk.com/ http://bbs.hiapk.com/ http://bbs.gfan.com/ http://bbs.anzhi.com/ http://www.ap ...

  3. 【转】VC中TRACE

    原文网址:http://blog.csdn.net/yangsen2016/article/details/1636996 TRACE宏对于VC下程序调试来说是很有用的东西,有着类似printf的功能 ...

  4. 【转】win7与ubuntu双系统,删除ubuntu后,启动错误error:no such partition grub rescue的修复--不错

    原文网址:http://blog.sina.com.cn/s/blog_541900d50101eu9r.html win7于ubuntu双系统,进入windows后直接格式化硬盘分区将ubuntu删 ...

  5. NOI2015

    D1T1 并查集. #include<cstdio> #include<cstdlib> #include<iostream> #include<fstrea ...

  6. NUnit - 使用感受

    Nunit使用 最近项目开始大量使用Nunit, 发现Nunit还是有很多好处的. 1. 测试驱动逻辑,这样可以尽最大可能减少“修改”引入的Bug. 如果你修改了一些东西,导致Case跑不过.请检查你 ...

  7. Odometer使用JavaScript和CSS制作数字滑动效果

    Odometer是一个使用JavaScript和CSS技术,制作出数字上下滑动的动画效果插件,有点类似与我们的天然气的读数的动画效果,这个插件是轻量级的,压缩版本只有3kg,使用CSS3动画技术,所以 ...

  8. Eclipse+Java+OpenCV246人脸识别

    1.环境搭建:见上一篇博客 整个项目的结构图: 2.编写DetectFaceDemo.java,代码如下: package com.njupt.zhb.test; import org.opencv. ...

  9. unity3d 学习笔记(一)

    操作:按下shit 点击坐标轴中心 切换透视图 动画烘焙的概念:相当于把原来的控制器动画或者IK(骨骼)动画所有塌陷为逐帧动画,导出的时候必须选这一项 着色器:从技术的角度来看,着色器是渲染器的一个部 ...

  10. JavaScript 中的事件设计

    1. 事件绑定的几种方式  主要介绍一下 最常用的事件设计 其他就稍微带过. 直接在代码里面添加onclick指定函数名字. B) 在JS代码中通过dom元素的onclick等属性 这种做法this表 ...