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 ...
随机推荐
- ASP.NET性能监视参数详解
性能监视器- Performance Monitor 性能监视器是Windows自带的系统资源和性能监视工具. 性能监视器能够量化地提供CPU使用率, 内存分配状况, 异常派发情况, 线程调度频率等信 ...
- Problem B The Blocks Problem(vector的使用)
题目链接:Problem B 题意:有n块木块,编号为0~n-1,要求模拟以下4种操作(下面的a和b都是木块编号) 1. move a onto b: 把a和b上方的木块全部归位,然后把a摞在b上面. ...
- Stack trace对性能的影响
package ceshi; public class ExceptionTest { public long maxLevel = 20; public static void main(Strin ...
- GraphLab:新的面向机器学习的并行框架
大规模图数据计算引起了许多知名公司的关注,微软提出了用于图数据匹配的Horton - Querying Large Distributed Graphs(Link:http://research.mi ...
- html常用标签有哪些
html看似复杂,其实常用的标签并不多,这里总共介绍一些html的常用标签 文字处理: ①标题:<h1> to <h6> ②段落:<p>文字段落</p> ...
- 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
- 【双模卡的相关知识】解SIM卡前需要知道的信息(SIM年分和厂商识别)
<ignore_js_op> 二.SIM版本问题SIM卡的版本有两种说法,一是有些是制造厂制定的,二是电信公司的制定.下面以移动为例,目前我们手里的SIM有几种版本:v0.v1.v2.v3 ...
- Google日历添加农历、节日和天气插件(步骤)
Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
在Android中调用其他程序进行相关处理,几乎都是使用的Intent,所以,Email也不例外,所谓的调用Email,只是说Email可以接收Intent并做这些事情 我们都知道,在Android中 ...
- installation - How to install Synaptic Package Manager? - Ask Ubuntu
installation - How to install Synaptic Package Manager? - Ask Ubuntu How to install Synaptic Package ...