题目传送门

题意:训练指南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. [Android] 深入浅出Android App耗电量统计

    reference to : http://www.cnblogs.com/hyddd/p/4402621.html 前言 在Android统计App耗电量比较麻烦,直至Android 4.4,它仍没 ...

  2. (转)Ehcache 整合Spring 使用页面、对象缓存

    Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...

  3. android DisplayMetrics 获取屏幕分辨率

    Android 提供DisplayMetircs 类可以很方便的获取分辨率.下面介绍 DisplayMetics 类: Andorid.util 包下的DisplayMetrics 类提供了一种关于显 ...

  4. LoadRunner 思考时间与事务响应时间的区别与关系

    LoadRunner 思考时间与事务响应时间的区别与关系   思考时间lr_think_time 就是一个事务要开始时思考的时间;比如 你要点击一个 登录按钮 我们都要点击这个按钮要先思考下 就是人为 ...

  5. EasyUi – 4.datagrid

    测试的时候用Json来测试就好啦. <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> ...

  6. Android Matrix

    转自 :http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#code Matrix的数学原理 平移变换 旋转变换 缩放变换 错切 ...

  7. WCF分布式开发必备知识(3):Web Service 使用

    参考地址:http://www.cnblogs.com/zhili/p/WebService.html 一.WebService概述 SOAP.WSDL.UDDISOAP(Simple Object ...

  8. 解决Pyqt打包后运行报错:应用程序无法启动 因为程序的并行配置不正确

    做了一个生成二维码的小程序:http://www.cnblogs.com/dcb3688/p/4241048.html 直接运行脚本没问题,用pyinstaller打包后再运行就直接报错了: 应用程序 ...

  9. 【Java EE 学习 20】【使用过滤器实现登陆验证、权限认证】【观察者模式和监听器(使用监听器实现统计在线IP、登录IP 、踢人功能)】

    一.使用过滤器实现登录验证.权限认证 1.创建5张表 /*使用过滤器实现权限过滤功能*/ /**创建数据库*/ DROP DATABASE day20; CREATE DATABASE day20; ...

  10. Quartz:Cron Expressions

    原文地址:http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontrigger.html 注意: 位也可能是7位, ...