大意:猜数据结构是栈、队列或者优先队列,可能为两种以上,也可能都不是。

水题。。

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的更多相关文章

  1. [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 ...

  2. 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 ...

  3. 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 ...

  4. 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. ...

  5. STL UVA 11995 I Can Guess the Data Structure!

    题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...

  6. UVa 11995 I Can Guess the Data Structure!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

  7. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  8. UVA - 11995 I Can Guess the Data Structure!(模拟)

    思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...

  9. Trainning Guide, Data Structures, Example

    最近在复习数据结构,发现这套题不错,题目质量好,覆盖广,Data Structures部分包括Example,以及简单,中等,难三个部分,这几天把Example的做完了, 摘要如下: 通过这几题让我复 ...

随机推荐

  1. js实现删除确认提示框

    js实现删除确认提示框 一.实例描述 防止用户小心单击了“删除”按钮,在用户单击“删除”按钮后,给出一个提示,让用户确认此次操作是否正确. 二.效果 三.代码 <!DOCTYPE html> ...

  2. OpenCV —— 图像变换

    将一副图像转变成另一种表现形式 ,比如,傅里叶变换将图像转换成频谱分量 卷积 —— 变换的基础 cvFilter2D  源图像 src 和目标图像 dst 大小应该相同 注意:卷积核的系数应该是浮点类 ...

  3. java中的九大隐藏变量.

          javax.servlet.jsp.JspWriter类型,代表输出流的对象.作用域为page(页面执行期) request:javax.servlet.ServletRequest的子类 ...

  4. 算法导论——lec 12 平摊分析与优先队列

    在平摊分析中,运行一系列数据结构操作所须要的时间是通过对运行的全部操作求平均得出.反映在不论什么情况下(即最坏情况下),每一个操作具有平均性能.掌握了平摊分析主要有三种方法,聚集分析.记账方法.势能方 ...

  5. Property-属性动画

    今天第一次接触到属性动画.参考着 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38067475 的博客,自己学习下. 它的区别跟 ...

  6. Android 使用AIDL实现进程间的通信

    在Android中,如果我们需要在不同进程间实现通信,就需要用到AIDL技术去完成. AIDL(android Interface Definition Language)是一种接口定义语言,编译器通 ...

  7. Code froces 831 A. Unimodal Array

    A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. POJ 1118 Lining Up 直线穿过最多的点数

    http://poj.org/problem?id=1118 直接枚举O(n^3) 1500ms能过...数据太水了...这个代码就不贴了... 斜率排序O(n^2logn)是更好的做法...枚举斜率 ...

  9. USACO 2009 Dec cow toll paths 过路费-floyd

    这道题首先要明确一点,那就是当你从一个点走到自己时,也是需要花费这个点点权值的费用.这个点卡了我两次QWQ 然后我比较喜欢分两步搞: 首先,我们利用floyd的一个性质:就是在更新其他点之间的路线时要 ...

  10. .condarc(conda 配置文件)

    Configuration - Conda documentation .condarc以点开头,一般表示 conda 应用程序的配置文件,在用户的家目录(windows:C:\\users\\use ...