11995 - I Can Guess the Data
大意:猜数据结构是栈、队列或者优先队列,可能为两种以上,也可能都不是。
水题。。
STL 记得判断是否为空
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int MAXN=1000+24;
int num[MAXN],action[MAXN],n;
bool check_stack()
{
stack<int> a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
} bool check_queue()
{
queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.front()) return false;
a.pop();
}
}
return true;
} bool check_pq() //check priority queue
{
priority_queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
bool s,q,p;
for(int i=0;i<n;i++)
scanf("%d%d",&action[i],&num[i]);
s=q=p=0;
s=check_stack();
q=check_queue();
p=check_pq();
if(s && !q && !p) printf("stack\n");
else if(!s && q && !p) printf("queue\n");
else if(!s && !q && p) printf("priority queue\n");
else if (s ||q ||p) printf("not sure\n");
else printf("impossible\n");
}
}
11995 - I Can Guess the Data的更多相关文章
- [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!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- Trainning Guide, Data Structures, Example
最近在复习数据结构,发现这套题不错,题目质量好,覆盖广,Data Structures部分包括Example,以及简单,中等,难三个部分,这几天把Example的做完了, 摘要如下: 通过这几题让我复 ...
随机推荐
- mongo数据库--非关系型数据库
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFuZ2xpdXFpbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- js---08函数 定时器
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 3.索引与string进行映射实现高效查找
#include <iostream> #include <typeindex>//类型索引 #include <unordered_map>//红黑树 #incl ...
- Android 如何获取Android RecyclerView滑动的距离
如何获取 RecyclerView 的滑动距离? RecyclerView 虽然有getScrollX() 和 getScrollY(), 但是测试发现这两个函数总是返回0,太无语了.因此想到了下面几 ...
- 【基础篇】EditText的一些属性设置
设置EditText的背景颜色 private test_editText=null; test_editText= (EditText) findViewById(R.id.EditTextInp ...
- idea配置spark运行模式
1. 配置运行参数: Menu -> Run -> Edit Configurations -> 选择 + -> Application -Dspark.master=lo ...
- C++遍历目录+_finddata_t结构体用法
Struct _finddata_t是用来存储文件各种信息的结构体,使用这个结构体要引用的头文件为“ #include <io.h>”它的结构体定义如下: struct _finddata ...
- STL_算法_查找算法(search、find_end)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) search //从左往右找第一个符合条件的子区间 全部容器适用 find_end //从右往左找 ...
- iOS Dev (51)加急审核
https://developer.apple.com/appstore/contact/? topic=expedite
- 堆-heap
#include <vector> #include <cstdio> using namespace std; class Heap { private : vector&l ...