码迷,mamicode.com
首页 > 其他好文 > 详细

uva 11995 I Can Guess the Data Structure 数据结构

时间:2015-05-17 12:21:40      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:uva 11995   i can guess the data   数据结构   

// uva 11995 数据结构
// 给你一些操作,确定是队列还是栈还是优先队列(数值大的优先级大)
// 简单题,练练基础吧相当于

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ceil(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define gcd __gcd
#define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
#define popCount __builtin_popcountll
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const long double PI = acos(-1.L);

template<class T> inline T lcm(const T& a, const T& b) { return a/gcd(a, b)*b; }
template<class T> inline T lowBit(const T& x) { return x&-x; }
template<class T> inline T maximize(T& a, const T& b) { return a=a<b?b:a; }
template<class T> inline T minimize(T& a, const T& b) { return a=a<b?a:b; }

const int maxn = 1008;

int n;
void solve(){
	priority_queue<int> pque;
	queue<int> que;
	stack<int> st;
	int f,x;
	int flag1=1,flag2=1,flag3=1;
	for (int i=0;i<n;i++){
		scanf("%d%d",&f,&x);
		if(f==1){
			pque.push(x);
			que.push(x);
			st.push(x);
		}else {
			if (st.empty() || x!=st.top()){
				flag3 = 0;
			}
			if (pque.empty() || x!=pque.top()){
				flag1 = 0;
			}
			if (que.empty() || x!=que.front()){
				flag2 = 0;
			}
			if (!st.empty())
				st.pop();
			if (!pque.empty())
				pque.pop();
			if (!que.empty())
				que.pop();
		}
	}
	int sum = flag1 + flag2 + flag3;
	if (sum>=2){
		puts("not sure");
	}else if (sum==0){
		puts("impossible");
	}else {
		if (flag1)
			puts("priority queue");
		else if (flag2)
			puts("queue");
		else 
			puts("stack");
	}
}

int main() {
	//freopen("G:\\Code\\1.txt","r",stdin);
	while(scanf("%d",&n)!=EOF){
		solve();
	}
	return 0;
}

uva 11995 I Can Guess the Data Structure 数据结构

标签:uva 11995   i can guess the data   数据结构   

原文地址:http://blog.csdn.net/timelimite/article/details/45787273

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!