题意:给你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的更多相关文章

  1. [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 ...

  2. 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 ...

  3. 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 ...

  4. 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. ...

  5. STL UVA 11995 I Can Guess the Data Structure!

    题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...

  6. UVa 11995 I Can Guess the Data Structure!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

  7. UVA - 11995 I Can Guess the Data Structure!(模拟)

    思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...

  8. [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 ...

  9. Data Structure Stack: Reverse a stack using recursion

    http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...

随机推荐

  1. awk 的一个奇怪异常

    awk: cmd. line:1: (FILENAME=- FNR=192) fatal: print to "standard output" failed (No space ...

  2. Mybatis+SpringMVC的项目环境搭建

    一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  3. Matlab中sortrows函数解析

    一.问题来源 返回检索到的数据(按相关度排序)在原始数据中的索引. 二.问题解析 x = [1 4 3 5; 1 3 2 6]:sortrows(x)其结果是按照row来排列,默认首先排第一列,1和1 ...

  4. zoj 3365

    题意 给你一个序列  改变尽可能少的数使其成为公差为一 递增的等差数列 可以将给你的序列减去一个等差数列 即num[i] -= i,若得到的数全部相等, 则说明给你的序列本身就满足条件  则只要寻求n ...

  5. linux服务器初步印象,远程连接mysql数据库,传输文件,启动/关闭tomcat命令

    1.连接服务器数据库,以Navicat连接mysql为例 1.1 常规 新建连接,连接名,主机名或ip地址:127.0.0.1 端口:3306用户名:(服务器端)root密码:(服务器端)pwd 1. ...

  6. Python性能鸡汤

    http://pythoner.org/wiki/257/ 毫无疑问:Python程序没有编译型语言高效快速. 甚至Python拥护者们会告诉你Python不适合这些领域. 然而,YouTube已用P ...

  7. php的redis 操作类,适用于单台或多台、多组redis服务器操作

    redis 操作类,包括单台或多台.多组redis服务器操作,适用于业务复杂.高性能要求的 php web 应用. redis.php: <?php /* redis 操作类,适用于单台或多台. ...

  8. MetadataType的使用

    MetadataType的使用,MVC的Model层数据验证指定要与数据模型类关联的元数据类 using System.ComponentModel.DataAnnotations; //指定要与数据 ...

  9. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  10. ecos内核概览--bakayi译

    http://blog.csdn.net/wangzaiwei2006/article/details/6453423