uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)
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
题意:水。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
#define F(i,s,x) for(i=s;i<x;i++)
const double PI=acos(-1.0);
typedef long long LL;
int main(){
int n;
while(~SI(n)){
int x,t;
queue<int>q;
priority_queue<int>sq;
stack<int>S;
int a=1,b=1,c=1;
int temp=0;
while(n--){
SI(t);SI(x);
if(temp)continue;
if(t==1){
q.push(x);
sq.push(x);
S.push(x);
}
else{
if(q.empty())temp=1;
if(temp)continue;
if(q.front()!=x)a=0;
if(sq.top()!=x)b=0;
if(S.top()!=x)c=0;
q.pop();
sq.pop();
S.pop();
}
}
if(temp||(a+b+c==0))puts("impossible");
else if(a+b+c>1)puts("not sure");
else if(a)puts("queue");
else if(b)puts("priority queue");
else if(c)puts("stack");
}
return 0;
}
uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- 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. ...
- STL UVA 11995 I Can Guess the Data Structure!
题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...
- UVa 11995 I Can Guess the Data Structure!
做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...
- uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- UVA - 11995 I Can Guess the Data Structure!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
随机推荐
- activity的横屏和竖屏设置
主要在清单文件这样配置: <application android:allowBackup="true" android:icon="@drawable/ic_la ...
- [C#编程参考]把图像转换为数组的两种实现
当一个程序和一个图片放在一起,无非有两种操作: 第一种,就是传输这个图片,在传输图片之前要首先把这个图片变成byte类型的数组.所以这时候我们用到的是图片的存储的数据,也就是图片属性中的大小.我们并不 ...
- Java "JSON中无分隔符日期字符串处理"
Json 中日期类型数据处理,服务端传输的日期没有分隔符,一般格式就两种,[20151212121212]即yyyyMMddhhmmss和[121212]hhmmss import java.text ...
- Android 开发笔记“浅谈DDMS视图”
DDMS 的全称是Dalvik Debug Monitor Service,即Dalvik调试监控服务,是一个可视化的调试监控工具.它主要是对系统运行后台日志的监控,还有系统线程,模拟器状态的监控.此 ...
- 简单的Coretext 图文混排
在很多新闻类或有文字展示的应用中现在都会出现图文混排的界面例如网易新闻等,乍一看去相似一个网页,其实这样效果并非由UIWebView 加载网页实现.现在分享一种比较简单的实现方式 iOS sdk中为我 ...
- Android Blur效果之FastBlur
Blur 自从iOS系统引入了Blur效果,也就是所谓的毛玻璃.模糊化效果,磨砂效果,各大系统就開始竞相模仿,这是一个怎样的效果呢,我们现来看一些图: 这些就是典型的Blur效果,在iOS和MIUI中 ...
- JavaScript 高级程序设计(第3版)笔记——chapter6:面向对象的程序设计
一.创建对象 工厂模式.使用简单的函数创建对象,为对象添加属性和方法,然后返回对象.[问题:没有解决对象识别问题] 1 function createPerson(name, age) { 2 var ...
- DevExpress ASP.NET 使用经验谈(4)-CriteriaOperator的使用
上一节中,我们已经介绍了,使用CriteriaOperator表达式,获取对象数据. CriteriaOperator criteria = CriteriaOperator.Parse(" ...
- webform基础介绍及页面传值(session,cookie)、跳转页面
一,IIS 1.首先知道IIS是个什么东西:它是web服务器软件,安装在服务器上,接受客户端发来的请求,并传送给服务器端,然后响应请求并送回给客户端.类似于饭店里的服务员. 2.会安装IIS——控制面 ...
- database schema
数据中有4个Schema无法被删除 ● dbo, 具有db_owner或者db_ddl_admin 的用户,新创建对象默认schema就是dbo ● guest , 用来给guest 用户使用,这个s ...