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 ...
随机推荐
- input属性为number时,如何去掉右边的 +、-号
修改css /* 谷歌 */ input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearan ...
- vue前后分离---数据模拟
最近为在做CRM的前期工作,忙里偷闲写了个关于数据模拟方面的东西 主要是现在博客中满天都再说前后分离,但是还没有几个实际操作的---让许多新手{-_-} 方法一: 启动一个express静态服务器-- ...
- POI操作Excel详解,读取xls和xlsx格式的文件
package org.ian.webutil; import java.io.File; import java.io.FileInputStream; import java.io.FileN ...
- mpdf中文开发使用文档附demo实例
官网URL:http://www.mpdf1.com/mpdf/index.php github:https://github.com/mpdf/mpdf 官方开发手册,英文的:http://www. ...
- Chrome 调试技巧
Chrome 调试技巧 1.alert 这个不用多说了,不言自明. 可参考:https://www.cnblogs.com/Michelle20180227/p/9110028.html 2.cons ...
- Ubuntu上Qt+Tcp网络编程之简单聊天对话框
首先看一下实现结果: >>功能: (1)服务器和客户端之间进行聊天通信: (2)一个服务器可同时给多个客户端发送消息:(全部连接时) 也可以只给特定的客户端发送消息:(连接特定IP) ...
- Java+Selenium环境搭建
初学者---简单的selenium环境搭建: 1. 安装JAVA环境 2.下载eclipse 3.下载firefox (不要最高版本,容易出现selenium不兼容问题) 4. 下载selenium需 ...
- java之项目构建工具Gradle
介绍 Java 作为一门世界级主流编程语言,有一款高效易用的项目管理工具是 java 开发者共同追求的心愿和目标.显示 2000 年的 Ant,后有 2004 年的 Maven 两个工具的诞生,都在 ...
- python基础(2)-运算符&while循环
算术运算符 a=5; b=2; print(a+b);#result:7 desc:加 print(a-b);#result:3 desc:减 print(a*b);#result:10 desc:乘 ...
- [摘抄] SFM 和 Visual SLAM
来自知乎: SFM和vSLAM基本讨论的是同一问题,不过SFM是vision方向的叫法,而vSLAM是robotics方向的叫法. vSLAM所谓的mapping,vision方向叫structure ...