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. ...
随机推荐
- September 23rd 2016 Week 39th Friday
Even a small star shines in the darkness. 星星再小,也会发光. In the darkness, even a small star can shine. N ...
- NPOI 1.2.4教程 –日期函数
//Excel中有非常丰富的日期处理函数,在NPOI中同样得到了很好的支持.如下图: using NPOI.HSSF.UserModel; using NPOI.HPSF; using NPOI.PO ...
- Android-----overridePendingTransition的使用
1 Activity的切换动画指的是从一个activity跳转到另外一个activity时的动画. 它包括两个部分:一部分是第一个activity退出时的动画:另外一部分时第二个activity进入时 ...
- Memcached驱动(C#)
using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.IO; usin ...
- I-number
以下是真坑爹题目: 此题必须输出前导零,否则永远a不了 I-number Time Limit: 5000MS Memory limit: 65536K 题目描述 The I-number of x ...
- 【openGL】画圆
#include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...
- Oracle 【IT实验室】数据库备份与恢复之一:exp/imp(导出与导入&装库与卸库)
1.1 基本命令 1. 获取帮助 $ exp help=y $ imp help=y 2. 三种工作方式 (1)交互式方式 $ exp // 然后按提示输入所需要的参数 ...
- memcached基于socket访问memcache缓存服务器
memcached基于socket访问memcache缓存服务器 操作memcache常用三种方法: .memcache基于php_memcache.dll扩展(php扩展) .memcached基于 ...
- [Monitor] 监控规则定义
系统监控规则:
- 静态/动态函数库设计,王明学learn
静态/动态函数库设计 Linux应用程序设计中需要的外部函数主要由函数库和系统调用来提供. 两者区别: 一.函数库分类 函数库按照链接方式可分为: 1.静态链接库 对函数库的链接是放在编译时期(com ...