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 ...
随机推荐
- Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/List at
折腾了一下的时间,都没有找到解决的方案,在网上搜了一下答案都是让清理编译环境和重新打包之类的.就这样折腾一下,还没有解决问题.之所以会抛出找不到类的问题,需要排查你使用这个包的类是否存在,存在之后 查 ...
- Mybatis Learning Notes 1
Mybatis Learning Notes 主要的参考是博客园竹山一叶的Blog,这里记录的是自己补充的内容 实体类属性名和数据库不一致的处理 如果是实体类的结果和真正的数据库的column的名称不 ...
- 2012-2013 ACM-ICPC, NEERC, Central Subregional Contest C Sequence (打表)
打个表找找规律,到24445的时候乘2以后产生了0出现循环. 一般地,判断循环节是否存在可以用Floyd判圈算法. #include<bits/stdc++.h> using namesp ...
- iOS开发资源:推送通知相关开源项目--PushSharp、APNS-PHP以及Pyapns等
PushSharp (github) PushSharp是一个实现了由服务器端向移动客户端推送消息的开源C#库,支持 iOS (iPhone/iPad APNS). Android (C2DM/GC ...
- 产生式模型(生成式模型)与判别式模型<转载>
转自http://dongzipnf.blog.sohu.com/189983746.html 产生式模型与判别式模型 产生式模型(Generative Model)与判别式模型(Discrimiti ...
- Catalan 数
概要 在一些面试的智力题中会遇到此数的变形,如果完全不了解,直接想结果是很困难的,故在此简单介绍一下. 基本定义 Catalan 数的定义根据不同的应用环境有很多不同的定义方式,下面给出一个. ...
- CeontOS6.5安装php环境
港湾云主机重装操作系统之后xshell无法连接:重启ssh:# service sshd restart -bash: vim: command not found:输入 rpm -qa|grep v ...
- java在线聊天项目0.6版 解决客户端关闭后异常问题 dis.readUTF()循环读取已关闭的socket
服务端对try catch finally重新进行了定义,当发生异常,主动提示,或关闭出现异常的socket 服务器端代码修改如下: package com.swift; import java.io ...
- lsof指令使用简介
lsof替代了netstat和ps的全部工作.它可以带来那些工具所能带来的一切,而且要比那些工具多得多 最重要的是,当你给它传递选项时,默认行为是对结果进行“或”运算.因此,如果是用-i来拉出一个端口 ...
- mysql:破解MySQL密码的一种方法
1, 修改mysql配置文件/etc/my.cnf 12 [mysqld]skip_grant_tables 2, 重启mysql后直接用root用户登录(不用输入密码) 1 $ mysql -uro ...