uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;
int n;
int v[],u[]; int ck_q()
{
//cout<<"!!"<<endl;
queue<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.front();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
} int ck_s()
{
stack<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.top();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
} int ck_d()
{
priority_queue<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.top();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=; i<n; i++)
{
scanf("%d%d",&v[i],&u[i]);
}
int s=ck_s();
int q=ck_q();
int d=ck_d();
//cout<<s<<" "<<q<<" "<<d<<endl;
if(s&&!q&&!d)
printf("stack\n");
else if(!s&&q&&!d)
printf("queue\n");
else if(!s&&!q&&d)
printf("priority queue\n");
else if(!s&&!q&&!d)
printf("impossible\n");
else
printf("not sure\n");
}
return ;
}
uva 11995 I Can Guess the Data Structure stack,queue,priority_queue的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- 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. ...
- STL UVA 11995 I Can Guess the Data Structure!
题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...
- UVa 11995 I Can Guess the Data Structure!
做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...
- UVA - 11995 I Can Guess the Data Structure!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- [Data Structure] Stack Implementation in Python
We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...
- Data Structure Stack: Reverse a stack using recursion
http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...
随机推荐
- vi查找替换
:n,$s/value1/value2/g 从第n行到最后一行,将value1替换成value2
- MCM试题原文及翻译 AB题 2014美国数学建模竞赛
MCM试题原文及翻译 AB题 2014美国数学建模竞赛 原创翻译,如有瑕疵,敬请谅解. 转载请注明:过客小站 » MCM试题原文及翻译 AB题 2014美国数学建模竞赛 PROBLEM A: The ...
- IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set
在file-setting里面,找到maven的设置: 先加入一个环境变量 然后配置一个JVM的参数: -Dmaven.multiModuleProjectDirectory=$M2_HOME OK ...
- c缺陷与陷阱笔记-第一章 词法陷阱
1.运算符的贪心性,匹配最长的运算符,例如 n-->0,从-开始,-是运算符,--是运算符,-->就不是,所以是 n -- > 0,--是 a---b,-是,--是,,---不是,所 ...
- Git管理unity3d项目
如果小组中没有足够的专业版license,用不了unity3d自带的version control,可以使用git来对项目进行版本控制:只不过需要建一个.gitignore文件在git项目管理的根目录 ...
- xcode 树形管理 cocos2d-x的资源
把资源以目录的形式加入xcode中, 同时, 在加入时, 选择"Create Folder References for any added folders", 而不是默认的&q ...
- Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤
原文地址: Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤 - 网络资源是无限的 - 博客频道 - CSDN.NET http://blog.csdn.net/fen ...
- 24.allegro中光绘gerber[原创]
光绘 一,基本设置 或者: ------------------------------------- ------- ------- 二,需要设置内容: 1)顶层和底层: 2)内部布线层: 3)OU ...
- gitHub for windows设置网络代理
在公司网络环境下使用gitHub,一直出错,因为公司使用的代理.但是gitHub for windows无法设置代理. 可以通过C:\Users\admin\.gitconfig中,添加代理. 添加: ...
- Ubuntu安装已经下载好的文件包
默认的文件下载都在 ~/Downloads 文件夹里面. 按 ctrl+alt+t 打开命令. 1.解压下载好的文件包,如: tar -xvf Sublime\ Text\ 2.0.2.tar.bz2 ...