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 ...
随机推荐
- c# 重载运算符(+-|&)和扩展方法
通常我们需要对class的相加,相减,相乘 等重载以适应需求, 如caml查询的时候,我们可以定义一个caml类,然后来操作这些查询. 首先,我们定义一个class为Test public class ...
- Jquery.linq 使用示例
http://linqjs.codeplex.com/ /*Linq JS*/ //range var aa = Enumerable.range(1, 10).toArray(); var kk = ...
- 【Asp.Net MVC--资料汇总】杂七杂八
Html.RenderPartial与Html.RenderAction的区别 http://blog.sina.com.cn/s/blog_8278b1800100zkn0.html ASP.NET ...
- 提升SQL Server速度整理索引碎片
转载:http://wenku.baidu.com/view/f64c8a707fd5360cba1adbea.html SQL Server2005索引碎片分析和解决方法 毫无疑问,给表添加索引 ...
- hadoop+hbase
hadoop的配置见下面这篇文章 http://www.powerxing.com/install-hadoop-2-4-1-single-node/ Hadoop安装教程_单机/伪分布式配置_Had ...
- uniqueidentifier 数据类型(转)
想要产生这种唯一标识的格式的数据: 6F9619FF-8B86-D011-B42D-00C04FC964FF 应该怎么做呢?答: uniqueidentifier 数据类型可存储 16 字节的二进制 ...
- Strust2最基本使用
制作一个登陆表单,然后在另一个页面显示提交的内容,简单的一个小工程. 页面: //login.jsp <form action="login.action" method=& ...
- linux出现bash: ./java: cannot execute binary file 问题的解决办法
问题现象描述: 到orcal官网上下载了两个jdk: (1)jdk-7u9-linux-i586.tar.gz ------------>32位 (2)jdk-7u9-linux-x64.tar ...
- 【Linux常识篇(3)】文件及文件夹的ctime atime mtime的含义详解
首先可以使用stat 命令来查询文件的inode信息,其中包括ctime atime mtime [root@localhost ~]# stat sort2.txt File: 'sort2.txt ...
- 用 React 编写SVG图表
1.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="U ...