uva 11995 判别数据类型
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
- 题目大意:根据数据的操作<1>插入<2>删除判别是哪一种数据类型,有栈、队列、优先队列几种类型,如三种
都不符合输出impossbile,符合两种以上输出not sure,只符合一种的对应输出它的类型名称。
- #include <iostream>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #define Max 1010
- using namespace std;
- int N;
- int op[Max],num[Max];
- stack<int> S;
- queue<int> Q;
- priority_queue<int> PQ;
- int check_stack()
- {
- int i,t;
- while(!S.empty()) S.pop();
- for(i=;i<N;i++)
- {
- if(op[i]==)
- {
- if(S.empty()) return ;
- t=S.top();S.pop();
- if(t!=num[i]) return ;
- }
- else S.push(num[i]);
- }
- return ;
- }
- int check_queue()
- {
- int i,t;
- while(!Q.empty()) Q.pop();
- for(i=;i<N;i++)
- {
- if(op[i]==)
- {
- if(Q.empty()) return ;
- t=Q.front();Q.pop();
- if(t!=num[i]) return ;
- }
- else Q.push(num[i]);
- }
- return ;
- }
- int check_priorityqueue()
- {
- int i,t;
- while(!PQ.empty()) PQ.pop();
- for(i=;i<N;i++)
- {
- if(op[i]==)
- {
- if(PQ.empty()) return ;
- t=PQ.top();PQ.pop();
- if(t!=num[i]) return ;
- }
- else PQ.push(num[i]);
- }
- return ;
- }
- int main()
- {
- int i;
- int s,q,pq;
- while(scanf("%d",&N)!=EOF)
- {
- for(i=;i<N;i++) scanf("%d %d",op+i,num+i);
- s=check_stack();
- q=check_queue();
- pq=check_priorityqueue();
- if(!s && !q && !pq) printf("impossible\n");
- else if(s && !q && !pq) printf("stack\n");
- else if(!s && q && !pq) printf("queue\n");
- else if(!s && !q && pq) printf("priority queue\n");
- else printf("not sure\n");
- }
- return ;
- }
uva 11995 判别数据类型的更多相关文章
- [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 ...
- 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!(数据结构练习)
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里的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!(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!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- 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. ...
- UVA - 11995 模拟
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...
随机推荐
- es的插件 ik分词器的安装和使用
今天折腾了一天,在es 5.5.0 上安装ik.一直通过官方给定的命令没用安装成功,决定通过手工是形式进行安装.https://github.com/medcl/elasticsearch-analy ...
- 文字自动自左向右滚动的js代码
重要的一点,就是scrollLeft一直在变化.对象一直在移动,参照物没有动. 代码: css: #div1{display:black;width:110px;height:50px;line-he ...
- (六)使用Docker镜像(下)
1. 创建镜像 创建镜像的方法有三种: 基于已有镜像的容器创建 基于本地模板导入 基于Dockerfile创建 1.1 基于已有镜像的容器创建 该方法主要是使用docker commit命令,其格式 ...
- 各种分布(distribution)
正态分布(Normal distribution),又名高斯分布(Gaussian distribution).若随机变量X服从一个数学期望为μ.方差为σ^2(标准差为σ)的正态分布,记为N(μ,σ^ ...
- 实 Jordan 标准型和实 Weyr 标准型
将学习到什么 本节讨论关于实矩阵的实形式的 Jordan 标准型,也讨论关于复矩阵的另外一种形式的 Jordan 标准型,因为它在与交换性有关的问题中很有用. 实 Jordan 标准型 假设 \( ...
- OpenCascade:屏闪问题。
1.在OnDraw中同时调用用V3d_View::Redaw()和 V3d_View::FitAll();可暂时解决. 2.在OnDraw中同时调用用V3d_View::Update();
- 自己开发一个APP需要多少钱
广州APP开发公司[启汇网络]经常遇到有开发定制APP软件需求的企业,通常第一句问的就是“开发一款APP需要多少钱”,在做完客户行业的市场调查后,再了解客... 广州APP开发公司[启汇网络]经常遇到 ...
- null 理解
值 null 特指对象的值未设置.它是 JavaScript 基本类型 之一. 语法节 null 描述节 值 null 是一个字面量,它不像undefined 是全局对象的一个属性.null 是表示缺 ...
- servlet多文件上传(带进度条)
需要commons-fileupload-1.3.jar和commons-io-2.4.jar的支持 页面效果:(图片文件都可以) (1)进度标识类 public class UploadStatus ...
- MySQL插入SQL语句后在phpmyadmin中注释显示乱码
自己写一个建一个简单的数据表,中间加了个注释,但是用PHPmyadmin打开后发现注释不对. 就先查询了一下sql 语句 发现SQL 语句并没有问题,感觉像是显示编码的问题,就先用set names ...