UVA 1995 I can guess the structer

模 拟

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 #include<queue>
 9 #include<stack>
10 using namespace std;
11 int read(){
12     int x=0,f=1;char ch=getchar();
13     while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
14     while(ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
15     return x*f;
16 }
17 priority_queue<int>q;
18 stack<int>st;
19 queue<int>que;
20 int n;
21 int x,y;
22 bool flag_st,flag_qu,flag_pr;
23 int main(){
24 /*    freopen("qu.in","r",stdin);
25     freopen("qu.out","w",stdout);*/
26
27     while(scanf("%d",&n)!=EOF){
28         int i,j;
29         flag_pr=flag_qu=flag_st=1;
30         while(!q.empty()) q.pop();
31         while(!st.empty()) st.pop();
32         while(!que.empty()) que.pop();
33         for(i=1;i<=n;i++){
34             scanf("%d%d",&x,&y);
35             if(x==1){
36                 q.push(y);
37                 st.push(y);
38                 que.push(y);
39             }
40             else{
41                 if(q.empty() || q.top()!=y)flag_pr=0;
42                 if(st.empty() || st.top()!=y)flag_st=0;
43                 if(que.empty() || que.front()!=y)flag_qu=0;
44                 if(!q.empty())q.pop();
45                 if(!st.empty()) st.pop();
46                 if(!que.empty()) que.pop();
47             }
48         }
49         int cnt=0;
50         if(flag_st)cnt++; if(flag_pr)cnt++; if(flag_qu)cnt++;
51         if(cnt>1){
52             printf("not sure\n");
53             continue;
54         }
55         if(flag_st && !flag_pr && !flag_qu)printf("stack\n");
56         if(!flag_st && !flag_pr && flag_qu)printf("queue\n");
57         if(!flag_st && flag_pr && !flag_qu)printf("priority queue\n");
58         if(!flag_st && !flag_pr && !flag_qu)printf("impossible\n");
59     }
60     return 0;
61 }
时间: 2024-10-28 12:35:14

UVA 1995 I can guess the structer的相关文章

uva 539 The Settlers of Catan(回溯)

uva 539 The Settlers of Catan Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilderness. You are employed by a software company that jus

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica

[2016-02-03][UVA][514][Rails]

时间:2016-02-03 22:24:52 星期三 题目编号:UVA 514 题目大意:给定若干的火车(编号1-n),按1-n的顺序进入车站, 给出火车出站的顺序,问是否有可能存在 分析:    FIFO,用栈模拟一遍即可, 方法:    根据输入的顺序,从1-n开始,当前操作的为i 如果i是当前对应的编号,那么直接跳过(进入B) 如果不是,根据当前需求的编号,小于i,就从栈顶弹出一个元素, 看这个元素是否是需求的,是则继续.否则NO 1 2 3 4 5 6 7 8 9 10 11 12 13

快速幂取模(POJ 1995)

http://poj.org/problem?id=1995 以这道题来分析一下快速幂取模 a^b%c(这就是著名的RSA公钥的加密方法),当a,b很大时,直接求解这个问题不太可能 利用公式a*b%c=((a%c)*b)%c 每一步都进行这种处理,这就解决了a^b可能太大存不下的问题,但这个算法的时间复杂度依然没有得到优化 由此可以用快速幂算法优化: http://www.cnblogs.com/qlky/p/5020402.html 再结合取模公式: (a + b) % p = (a % p