题目传送门

题意:训练指南P186

分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法

#include <bits/stdc++.h>
using namespace std; int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
stack<int> sta;
queue<int> que;
priority_queue<int, vector<int>, less<int> > pque;
bool flag1 = true, flag2 = true, flag3 = true;
for (int op, x, y, i=1; i<=n; ++i) {
scanf ("%d%d", &op, &x);
if (op == 1) {
sta.push (x); que.push (x); pque.push (x);
}
else {
if (sta.empty ()) flag1 = false;
else {
y = sta.top (); sta.pop ();
if (y != x) flag1 = false;
}
if (que.empty ()) flag2 = false;
else {
y = que.front (); que.pop ();
if (y != x) flag2 = false;
}
if (pque.empty ()) flag3 = false;
else {
y = pque.top (); pque.pop ();
if (y != x) flag3 = false;
}
}
}
if (!flag1 && !flag2 && !flag3) puts ("impossible");
else if ((flag1 && flag2) || (flag1 && flag3) || (flag2 && flag3)) puts ("not sure");
else if (flag1) puts ("stack");
else if (flag2) puts ("queue");
else puts ("priority queue");
} return 0;
}

  

STL UVA 11995 I Can Guess the Data Structure!的更多相关文章

  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! STL 模拟

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

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

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

  5. UVa 11995 I Can Guess the Data Structure!

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

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

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

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

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

  8. uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)

    11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...

  9. UVA 11995 STL 使用

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

随机推荐

  1. ASIHTTPRequest详解 [经典]

    ASIHTTPRequest 对CFNetwork API进行了封装,并且使用起来非常简单,用Objective-C编写,可以很好的应用在Mac OS X系统和iOS平台的应用程序中.ASIHTTPR ...

  2. September 18th 2016 Week 39th Sunday

    Be the king of the spiritual kingdom that is your heart. 在心灵的国土上,做自己的国王. Most often we are not able ...

  3. September 4th 2016 Week 37th Sunday

    The morning crowned the humble cloud with splendor. 晨光为谦逊的白云披上壮丽的光彩. Humility is a virtue. Many famo ...

  4. 使用drozer连接时提示:Could not find java. Please ensure that it is installed and on your path

    在安装drozer后使用 drozer.bat console connect命令提示如下错误(实际上我已经安装了jdk并添加了path) 参考上面的链接已经它的提示解决方法如下: 建立名为 .dro ...

  5. tableView 局部刷新

    //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:in ...

  6. 重温WCF之消息契约(MessageContract)(六)

    对于SOAP来说主要由两部分构成Header和Body,他们两个共同构成了SOAP的信封,通常来说Body保存具体的数据内容,Header保存一些上下文信息或关键信息.比如:在一些情况下,具有这样的要 ...

  7. Arch Linux 安装、配置、美化和优化

    国庆假期玩了下Arch Linux,发现这货跟Ubuntu之流相差甚远,甚难调教,而且安裝过程全命令行,会有各种问题,各种知识... --- 安装引导器--- -------------------- ...

  8. Windows 10 周年更新正式版下载 + win10 快捷键

    Windows 10 周年更新正式版  360云资源总汇(施工中): https://yunpan.cn/c6Svi7Az52XBs (提取码:e5dd)今后提到周年更新版.1607版或RS1版,都是 ...

  9. js 上传文件后缀名的判断 var flag=false;应用

    js 上传文件后缀名的判断  var flag=false;应用 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...

  10. python学习第二天

    dict字典 把数据放入dict:直接赋值.初始化时指定 pop删除key set集合 add添加元素 remove删除元素 字符串str是不可变对象,对字符串的操作都会返回新的字符串 pass 什么 ...