UVa 11995 I Can Guess the Data Structure!
做道水题凑凑题量,=_=||。
直接用STL里的queue、stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空。
#include <bits/stdc++.h>
using namespace std; void scan( int &x )
{
char c;
while( c = getchar(), c < '' || c > '' );
x = c - '';
while( c = getchar(), c >= '' && c <= '' ) x = x* + c - '';
} const int maxn = + ;
int t[maxn], d[maxn]; bool is_queue(int n)
{
queue<int> Q;
for(int i = ; i < n; i++)
{
if(t[i] == ) Q.push(d[i]);
else
{
if(Q.empty()) return false;
int x = Q.front(); Q.pop();
if(x != d[i]) return false;
}
}
return true;
} bool is_stack(int n)
{
stack<int> S;
for(int i = ; i < n; i++)
{
if(t[i] == ) S.push(d[i]);
else
{
if(S.empty()) return false;
int x = S.top(); S.pop();
if(x != d[i]) return false;
}
}
return true;
} bool is_p_queue(int n)
{
priority_queue<int> Q;
for(int i = ; i < n; i++)
{
if(t[i] == ) Q.push(d[i]);
else
{
if(Q.empty()) return false;
int x = Q.top(); Q.pop();
if(x != d[i]) return false;
}
}
return true;
} int main()
{
//freopen("in.txt", "r", stdin); int n;
while(scanf("%d", &n) == )
{
for(int i = ; i < n; i++) { scan(t[i]); scan(d[i]); }
bool f1 = is_queue(n);
bool f2 = is_stack(n);
bool f3 = is_p_queue(n);
int cnt = (int)f1 + (int)f2 + (int)f3;
if(cnt > ) puts("not sure");
else if(cnt == ) puts("impossible");
else
{
if(f1) puts("queue");
if(f2) puts("stack");
if(f3) puts("priority queue");
}
} return ;
}
代码君
UVa 11995 I Can Guess the Data Structure!的更多相关文章
- [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 stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- UVA - 11995 I Can Guess the Data Structure!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)
11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
随机推荐
- Sql例子Sp_ExecuteSql 带参数
Declare @i int, @projectCount int ) --参数 ) ) ) ) ) ) --循环变量起始 --得到所有的项目 select @projectCount = count ...
- Linux/Ubuntu常用快捷键
问题描述: Linux/Ubuntu常用快捷键 问题解决: +++++++++++++++++++ 全局系统 +++++++++++++++++++++ Alt + F1:相当于w ...
- 【BZOJ】【2879】【NOI2012】美食节
网络流/费用流 跟 BZOJ 1070 修车 几乎是一道题,只是这题“要修的车”(即菜)多了很多……几乎是从$n$变成了$n^2$,所以建图的时候就得动态加点…… 也就是说,当一个厨师已经确定了他的后 ...
- 【HDOJ】【1754】I Hate It
线段树 这是一道线段树的裸题……带单点修改的RMQ 为什么我会想到写这么一道傻逼题呢?是因为这样……
- 一个碉堡的swing类
今天遇到一个掉了一笔的swing类.可以完美的解决JFrame下设置背景的问题.任意size.太掉了.特记于此 import java.awt.*; import java.awt.image.Buf ...
- 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台
经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- hdu 1850 Being a Good Boy in Spring Festival 博弈论
求可行的方案数!! 代码如下: #include<stdio.h> ]; int main(){ int n,m; while(scanf("%d",&n)&a ...
- jmeter 使用聚合报告分析jtl文件
对于jmeter测试生成产生的jtl文件除了使用jemter插件来产生csv或者结果,还可以直接用聚合报告来打开,下面来介绍一下怎么操作. 1. 产生jtl文件 注意,默认情况下聚合报告插件只能分析聚 ...
- Java传入参数个数不确定可用(Type ... values)
/** * 可变长的参数. * 有时候,我们传入到方法的参数的个数是不固定的,为了解决这个问题,我们一般采用下面的方法: * 1. 重载,多重载几个方法,尽可能的满足参数的个数.显然这不是什么好办法. ...