【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure!
思路:边读边模拟,注意empty的判断!
代码如下:
#include<iostream>
#include<queue>
#include<stack>
using namespace std; int main(){
queue<int> q;
priority_queue<int> pri_q;
stack<int> sta;
int n;
while(cin>>n){
while(!q.empty()) q.pop(); //清空data
while(!pri_q.empty()) pri_q.pop();
while(!sta.empty()) sta.pop(); int a,b,c; a=b=c=;
while(n--) {
int op,x;
cin>>op>>x;
if(op == ){
if(a) q.push(x);
if(b) pri_q.push(x);
if(c) sta.push(x);
}
else {
if(a) if(q.empty()) a=; else {a= q.front()==x; q.pop();}
if(b) if(pri_q.empty()) b=; else{b= pri_q.top()==x; pri_q.pop();}
if(c) if(sta.empty()) c=; else{c= sta.top()==x; sta.pop();}
}
}
if(!a && !b &&!c) cout<<"impossible";
else
if((a&&b) || (a&&c) ||(b&&c)) cout<<"not sure";
else{
if(a) cout<<"queue";
else if(b) cout<<"priority queue";
else cout<<"stack";
}
cout<<"\n";
}
return ;
}
【暑假】[实用数据结构]UVa11995 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 ...
- UVA11995 I Can Guess the Data Structure!
思路 简单题,用栈,队列,优先队列直接模拟即可 代码 #include <cstdio> #include <algorithm> #include <cstring&g ...
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- 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 ...
- 面试总结之数据结构(Data Structure)
常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- 【暑假】[实用数据结构]范围最小值问题(RMQ)
范围最小值问题: 提供操作: Query(L,R):计算min{AL ~ AR } Sparse-Table算法: 定义d[i][j]为从i开始长度为2j的一段元素的最小值.所以可以用递推的方法表示. ...
- 【暑假】[实用数据结构]UVAlive 3026 Period
UVAlive 3026 Period 题目: Period Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
随机推荐
- 只有innoDB才允许使用外键
1.只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用InnoDB引擎. 2.注意: 1.必须使用InnoDB引擎: 2.外键必须建立索引(INDEX): 3.外键绑定关系这里使用了“ O ...
- java中什么时候该用static修饰方法?有什么好处或者坏处?
当一个方法或者变量需要初始化加载,或者是经常被调用的时候可以加上static.用static修饰的方法可以用类名直接调用,不用的一定要先实例化一个对象然后才可以调用比如 person这个类里面有一个方 ...
- 2014-9-17二班----8 web project
http://localhost:8080/rwkj1/indexServlet 地址请求后,,,,浏览器 地址栏没有变化 package cn.rwkj.servlet; import java ...
- Servlet的应用
1.重定向 HttpServletRequest接口提供的sendRedirect()方法用于生产302响应码和Location响应头,从而通知客户端去重新访问Location响应头中指定的U ...
- 前端自动化工具:Grunt使用教程
1.下载node.js,然后将node.exe文件所在的目录加入path环境变量 2.安装npm管理工具 2.1.下载npm源码,解压到npm文件夹里,不要把npm放在和node.exe相同的文件夹 ...
- 数组 寻找最大的第k个数
int Partion(int asy[],int begin,int end) { int k=begin; int key=asy[end]; for(int i=begin;i<=end; ...
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序(老罗学习笔记2)
在前一篇文章中,我们介绍了如何在Ubuntu上为Android系统编写Linux内核驱动程序.在这个名为hello的Linux内核驱动程序中,创建三个不同的文件节点来供用户空间访问,分别是传统的设备文 ...
- C++ STL之set的基本操作
set是集合,虽然也存在键值和实值,不过两者根本就是同一个值,键值的设置完全就是为了满足红黑树的底层结构,set操作与map很像不过也有些不同. 1. set迭代器与map的不同: (1)set使用接 ...
- QWidget、QDialog、QMainWindow的异同点
简述 在分享所有基础知识之前,很有必要在这里介绍下常用的窗口 - QWidget.QDialog.QMainWindow. QWidget继承于QObject和QPaintDevice,QDialog ...
- Codeforces Round #273 (Div. 2)
A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...