STL UVA 11995 I Can Guess the Data Structure!
题意:训练指南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!的更多相关文章
- [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! STL 模拟
There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...
- 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里的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!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- 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 ...
- UVA 11995 STL 使用
There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...
随机推荐
- Java自定义注解开发
一.背景 最近在自己搞一个项目时,遇到可需要开发自定义注解的需求,对于没有怎么关注这些java新特性的来说,比较尴尬,索性就拿出一些时间,来进行研究下自定义注解开发的步骤以及使用方式.今天在这里记下, ...
- 用Mysqlbinlog备份BinLog文件
默认情况下, mysqlbinlog读取二进制文件[BinLog]并以文本的方式呈现[text format].mysqlbinlog可以直接地从本地读取Log,也可以读取远程的Log[--read- ...
- finla变量,方法和类
1.finla变量关键字可用于变量声明,一旦该变量被设定,就不可以再改变该变量的值,通常,有final定义的变量为常量 final关键字定义的变量必须在声明时对其进行赋值定义,final除了可以修饰基 ...
- probe函数何时调用的
转自:http://blog.csdn.net/xiafeng1113/article/details/8030248 Linux中 probe函数何时调用的 所以的驱动教程上都说:只有设备和驱动的名 ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- 攻城狮在路上(贰) Spring(一)--- 软件环境、参考书目等一览表
一.软件环境: 二.参考书目: <Spring 3.X 企业应用开发实战> 陈雄华.林开雄著 电子工业出版社出版 三.其他说明: spring 源码地址:https://github.co ...
- html5 svg
html5 svg <html > <body> <p>canvas 用js 绘画,是整幅画布,适合游戏 svg可放大,支持dom 操作,js事件 线性渐变.高斯模 ...
- js 横幅播放
js 横幅播放 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- wp8 入门到精通 聊天控件
<Grid > <Grid x:Name="bubble_right" VerticalAlignment="Center" RenderTr ...
- 在linux配置NFS用于RAC的搭建
rac的共享存储有很多种搭建方式,nfs是其中一种.生产环境一般不采用nfs,多用于测试. nfs搭建步骤大致分为如下: 1.划盘 给节点1挂载一块磁盘,并将磁盘分区,并格式化,再挂载 [root@n ...