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 ...
随机推荐
- UVA 11374 Airport Express (最短路)
题目只有一条路径会发生改变. 常见的思路,预处理出S和T的两个单源最短路,然后枚举商业线,商业线两端一定是选择到s和t的最短路. 路径输出可以在求最短路的同时保存pa数组得到一棵最短路树,也可以用di ...
- 测试类执行报错:AttributeError: 'Testlei' object has no attribute 'test_cases' 和data,unpack用法解析
a=[{"}] import unittest from ddt import ddt,data,unpack @ddt class Testlei(unittest.TestCase): ...
- java POI技术之导出数据优化(15万条数据1分多钟)
专针对导出excel2007 ,用到poi3.9的jar package com.cares.ynt.util; import java.io.File; import java.io.FileOut ...
- js的正则表达式总结
1.8-20位数字 or 字母 or 特殊字符 var reg = /^[0-9a-zA-Z!@#$%^&*()_+-/.]{8,20}$/; 2.8-20位 数字+字母+特殊字符 //正则 ...
- 多数据源连接Oracle报错,linux熵池耗尽问题
最近碰到了个很有意思的问题,springboot加载多数据源,遇到了在启动时数据库连接报错的问题. 报错信息: The error occurred while executing a query 然 ...
- shell脚本,计算学生分数的题目。
1.计算学生平均分数的值是多少? 2.计算每门课都大于80分的学生姓名.3.计算每门课都小于90分的学生姓名.
- Java InputStream、String、File相互转化
String --> InputStreamByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); Inp ...
- javase(5)_面向对象
一.概述 1.面向对象是一种思想,让我们由执行者变成指挥者,执行者是面向过程,指挥者是面向对象.例如人开冰箱门,开冰箱门这个动作应该属于门而不是人,冰箱自己最清楚门应该怎么开,人只是调用了冰箱的这个动 ...
- jquery 获取tbody下的第二个tr 及多级标签
<div id="testSlider"> <div class="esriTimeSlider ies-Slider" id="t ...
- linux内核启动修复
linux内核启动修复 首先看一下linux内核重要文件grub.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # gru ...