UVA11995 I Can Guess the Data Structure!
思路
简单题,用栈,队列,优先队列直接模拟即可
代码
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
queue<int> q;
stack<int> S;
priority_queue<int> pq;
int n;
int main(){
while(scanf("%d",&n)==1){
while(!q.empty())
q.pop();
while(!S.empty())
S.pop();
while(!pq.empty())
pq.pop();
bool isS=true,isq=true,ispq=true;
for(int i=1;i<=n;i++){
int opt,x;
scanf("%d %d",&opt,&x);
if(opt==1){
q.push(x);
pq.push(x);
S.push(x);
}
else{
if(q.empty())
isq=false;
if(pq.empty())
ispq=false;
if(S.empty())
isS=false;
if(isq){
int t=q.front();
if(t!=x)
isq=false;
q.pop();
}
if(ispq){
int t=pq.top();
if(t!=x)
ispq=false;
pq.pop();
}
if(isS){
int t=S.top();
if(t!=x)
isS=false;
S.pop();
}
}
}
if((!ispq)&&(!isq)&&(!isS))
printf("impossible\n");
else if((ispq)&&(!isq)&&(!isS))
printf("priority queue\n");
else if((!ispq)&&(isq)&&(!isS))
printf("queue\n");
else if((!ispq)&&(!isq)&&(isS))
printf("stack\n");
else
printf("not sure\n");
}
return 0;
}
UVA11995 I Can Guess the Data Structure!的更多相关文章
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...
- 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 ...
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- Finger Trees: A Simple General-purpose Data Structure
http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...
- Mesh Data Structure in OpenCascade
Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...
- ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
- leetcode Add and Search Word - Data structure design
我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...
随机推荐
- elk-(七)
最终架构确定为 logs--->blieb--->redis/kafka--->logstash--->es--->kibana 注意: geoip下载地址: wge ...
- react表单的一些小例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#winform窗体实现对sql server数据库的增删改查
1.运行效果截图 2.输入用户名,密码进行查询 查找成功则显示 查找不成功显示用户信息不存在 3.输入用户名与密码,向数据库中添加用户信息 添加后数据库表信息 4.查看全部信息 5.根据编号信息进行查 ...
- HTML经典模板总结(地址)
HTML经典模板总结 地址:http://download.csdn.net/tag/html%E6%A8%A1%E6%9D%BF?from=singlemessage
- JSON.parse()和JSON.stringify()的解析与用途
JSON.parse()和JSON.stringify()的解析与用途 1.parse用于从一个字符串中解析出json对象 如: var str = '{"name":" ...
- 关于STM32时钟系统
初学STM32,感觉最蛋疼的是它的时钟系统,每次看到它的那个时钟树就有点晕,虽然看了很多这方面的资料,甚至也已经写过很多STM32的模块代码,做过一些小项目,但一直还是对这一块模模糊糊,似懂非懂,所以 ...
- 43-3-STM32的CAN外设
1.STM32 的芯片中具有 bxCAN 控制器 (Basic Extended CAN), 它支持 CAN 协议 2.0A 和2.0B 标准. 2.外设中具有 3 个发送邮箱,发送报文的优先级可以使 ...
- python练习题-day13
1.获取移动平均值 def wrapper(fun): def inner(*args,**kwargs): ret=fun(*args,**kwargs) ret.__next__() return ...
- pandas处理时间序列(2):DatetimeIndex、索引和选择、含有重复索引的时间序列、日期范围与频率和移位、时间区间和区间算术
一.时间序列基础 1. 时间戳索引DatetimeIndex 生成20个DatetimeIndex from datetime import datetime dates = pd.date_rang ...
- Angela启动步骤
1.在web目录下执行 grunt watch (如果不在目录下执行不能识别,当然首先安装node.js) 2.随便改一个文件,会自动重新生成代码(在dest目录下会生成可执行的代码) 3.如果有de ...