题意:给你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. PAT-乙级-1034. 有理数四则运算(20)

    1034. 有理数四则运算(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求编写程序,计算2个有理 ...

  2. chardet安装

    1.下载 chardet-2.2.1.tar.gz (md5)   https://pypi.python.org/pypi/chardet#downloads 2.解压至C:\Python27\Li ...

  3. Tornado,表单处理,一样在行

    哟,处理流程还算自然... import os.path import random import tornado.httpserver import tornado.ioloop import to ...

  4. 在linux下,查看一个运行中的程序, 占用了多少内存

    1. 在linux下,查看一个运行中的程序, 占用了多少内存, 一般的命令有 (1). ps aux: 其中  VSZ(或VSS)列 表示,程序占用了多少虚拟内存. RSS列 表示, 程序占用了多少物 ...

  5. jquery.dataTables插件使用例子详解

    DataTables是一个jQuery的表格插件.这是一个高度灵活的工具,依据的基础逐步增强,这将增加先进的互动控制,支持任何HTML表格 效果图 代码 <!doctype html> & ...

  6. MapReduce编程系列 — 3:数据去重

    1.项目名称: 2.程序代码: package com.dedup; import java.io.IOException; import org.apache.hadoop.conf.Configu ...

  7. JQUERY 选择器 总结,比较全

    jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个 ...

  8. 锋利的JQuery-认识Jquery

    今天开始学习菜鸟的JQuery,这本书在一前看过一遍了,但是由于虽然看了,但是将近一年在工作中基本上没有用上,很是悲催,菜鸟想,用一到两个星期时间把这本书看一遍吧.就像菜鸟前面的jsdom一样,菜鸟写 ...

  9. Android 签名(8)签名前用Zipalign简单优化

    1 为什么要优化 Android SDK中包含一个“zipalign”的工具,它能够对打包的应用程序进行优化.在你的应用程序上运行zipalign,使得在运行时Android与应用程序间的交互更加有效 ...

  10. 1521. War Games 2(线段树解约瑟夫)

    1521 根据区间和 来确定第k个数在哪 #include <iostream> #include<cstdio> #include<cstring> #inclu ...