题目传送门

题意:训练指南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. IOS- 应用程序生命周期(前后台切换,应用的各种状态)详解

    iOS的应用程序的生命周期,还有程序是运行在前台还是后台,应用程序各个状态的变换,这些对于开发者来说都是很重要的. iOS系统的资源是有限的,应用程序在前台和在后台的状态是不一样的.在后台时,程序会受 ...

  2. Mysql之多源复制

    在复制时,可以有多个Master.这些Master不进行冲突检查拓扑到Slave.在使用多源复制时对Slave的表存储格式是有要求的,必须要基于table存储而非文件存储[require table ...

  3. NYOJ题目822画图

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtUAAAHzCAIAAABgzHaKAAAgAElEQVR4nO3dPVLjzBoG0LsJ514IsR

  4. java 接口与继承

    一.继承条件下的构造方法调用 运行 TestInherits.java 示例,观察输出,注意总结父类与子类之间构造方法的调用关系修改Parent构造方法的代码,显式调用GrandParent的另一个构 ...

  5. ps -C nginx --no-header |wc -l

    [root@ok ok]# ps --help|grep C -A all processes -C by command name -V,V show version L list format c ...

  6. 【PHP数组的使用】

    PHP数组使用关键字array标识,数组内的元素可以是任意类型,而且可以不是同一种类型,这和c.java不同. 遍历数组的方法可以使用foreach,也可以使用for循环 可以使用print_r或者v ...

  7. SQL语法中的子查询Subqueries

    记一下样子. 明白它的应用场景. SELECT account_id, product_cd, cust_id, avail_balance FROM account WHERE open_emp_i ...

  8. Install PIL on mac osX10.9

    follow this instruction: http://blog.csdn.net/liushuaikobe/article/details/8729652 and if you encoun ...

  9. ASP.NET 自定义URL重写 分类: ASP.NET 2014-10-31 16:05 175人阅读 评论(0) 收藏

    一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ...

  10. cordova+angularJS+ionic

    1.创建项目 2.路由 angular.module("starter",['ionic']) // 依赖 ionic 提供的ui-router .config(function ...