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 < ...
随机推荐
- c++ 容器类
#include <iostream> #include <vector> #include <list> #include <map> using n ...
- asp.net MVC日志插件Log4Net学习笔记二:保存日志到sqlserver的配置
1.写到sqlserver的配置: <!--保存到SQLSERVER数据库日志--> <log4net> <appender name="AdoNetAppen ...
- Hibernate-Validation的使用
首先是要加入下面两个包 hibernate-validator-4.1.0.Final.jar validation-api-1.0.0.GA.jar 如果在验证不通过的时候进行了添加.更新或删除操作 ...
- <转>struts2中Convention中的basePackage与locators配置种种
用了Convention插件来实现所谓的0配置, 1. struts.convention.package.locators.basePackage=com.ZTest.web.action 这个属性 ...
- uva 125
floyd 算法 如果存在无数条路 则存在a->a的路 a->b的路径数等于 a->i 和 i->b(0=<i<=_max) 路径数的乘积和 #includ ...
- ECNU-2574 Principles of Compiler
题意: 给出编译规则,求是否满足条件 A:= '(' B')'|'x'. B:=AC. C:={'+'A}. 其中{}表示里面的内容可以出现0次或者多次 注意点见代码注释 #include ...
- FZU-1921+线段树
简单的线段树. 记录MinVal 和 相应的ID即可 /* 线段树 */ #include<stdio.h> #include<string.h> #include<st ...
- Android 使用httpClient POST 模拟发送 multipart表单内容
使用的环境:apache-mime4j-0.6.jar,httpcore-4.3.2.jar,httpmime-4.3.3.jar try { HttpPost httpPost = new Http ...
- 安卓从业者应该关注:Android 6.0的运行时权限
Android 6.0,代号棉花糖,自发布伊始,其主要的特征运行时权限就很受关注.因为这一特征不仅改善了用户对于应用的使用体验,还使得应用开发者在实践开发中需要做出改变. 没有深入了解运行时权限的开发 ...
- Fetching android sdk component information
原文地址: Android Studio安装以及Fetching android sdk component information超时的解决方案 - sonyi - 博客园 http://www.c ...