11995 - I Can Guess the Data
大意:猜数据结构是栈、队列或者优先队列,可能为两种以上,也可能都不是。
水题。。
STL 记得判断是否为空
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int MAXN=1000+24;
int num[MAXN],action[MAXN],n;
bool check_stack()
{
stack<int> a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
} bool check_queue()
{
queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.front()) return false;
a.pop();
}
}
return true;
} bool check_pq() //check priority queue
{
priority_queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
bool s,q,p;
for(int i=0;i<n;i++)
scanf("%d%d",&action[i],&num[i]);
s=q=p=0;
s=check_stack();
q=check_queue();
p=check_pq();
if(s && !q && !p) printf("stack\n");
else if(!s && q && !p) printf("queue\n");
else if(!s && !q && p) printf("priority queue\n");
else if (s ||q ||p) printf("not sure\n");
else printf("impossible\n");
}
}
11995 - I Can Guess the Data的更多相关文章
- [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 stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- UVA - 11995 I Can Guess the Data Structure!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- Trainning Guide, Data Structures, Example
最近在复习数据结构,发现这套题不错,题目质量好,覆盖广,Data Structures部分包括Example,以及简单,中等,难三个部分,这几天把Example的做完了, 摘要如下: 通过这几题让我复 ...
随机推荐
- shape-自绘制简单图形
shape 可以绘制简单的图形,颜色等.它主要就是应用于selector 的一些状态. 本文内容参考自http://www.cnblogs.com/cyanfei/archive/2012/07/27 ...
- HTML5入门:HTML5的文档声明和基本代码
HTML5的文档声明: HTML5的文档声明,不同于HTML4.0和XHTML,它精简了许多代码,只保留<!DOCTYPE html>开头,必须位于HTML5文档的第一行,它可以用来告诉浏 ...
- css中margin上下外边距重叠问题
css的盒子模型里是这样规定两个对象之间的距离的:对象之间的间距是由两个对象的盒子模型的最终计算值得出来的,也就是说两个对象之间的间距就是两个对象的距离,但是当遇到两个对象一个有下外边距margin, ...
- ES6--基础语法(一)
一.支持环境:node.js完全支持,标准浏览器完全支持.二.测试环境: chrome下需要在script标签的最先开始的地方需要添加"use strict". firefox下需 ...
- LightOJ 1291 Real Life Traffic
Real Life Traffic Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. O ...
- Android之——短信的备份与还原
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47091281 眼下,Android手机中的一些软件能够实现手机短信的备份与还原操作 ...
- Vue 学习记录<2>
一.Vue https://vue-loader.vuejs.org/zh-cn/ https://vuejs-templates.github.io/webpack/structure.html
- Activity转换为View和把图片转换为View
package com.example.viewpager01; import java.util.ArrayList; import java.util.List; import android.a ...
- android抓取各种log的方法
1.logcat (四类log buffer是main,radio.system.events) adb wait-for-device logcat adb logcat -v time > ...
- php实现排列组合
php实现排列组合 一.总结 1.回溯:回溯的函数参数有些生疏了,记录递归的位置(pos或step),还要有东西(vis数组)来记录这个是否已经被访问 2.php全局变量的使用 :外部定义的普通变量, ...