zoukankan      html  css  js  c++  java
  • uva 11995 I Can Guess the Data Structure!

    解题思路:STL —— stack, queue, priority_queue

      1 ///////////////////////////////////////////////////////////////////////////
      2 //problem_id: uva 11995
      3 //user_id: SCNU20102200088
      4 ///////////////////////////////////////////////////////////////////////////
      5 
      6 #include <algorithm>
      7 #include <iostream>
      8 #include <iterator>
      9 #include <iomanip>
     10 #include <cstring>
     11 #include <cstdlib>
     12 #include <string>
     13 #include <vector>
     14 #include <cstdio>
     15 #include <cctype>
     16 #include <cmath>
     17 #include <queue>
     18 #include <stack>
     19 #include <list>
     20 #include <set>
     21 #include <map>
     22 using namespace std;
     23 
     24 ///////////////////////////////////////////////////////////////////////////
     25 #define lson l,m,rt<<1
     26 #define rson m+1,r,rt<<1|1
     27 ///////////////////////////////////////////////////////////////////////////
     28 
     29 ///////////////////////////////////////////////////////////////////////////
     30 const double EPS=1e-8;
     31 const double PI=acos(-1.0);
     32 
     33 const int x4[]={-1,0,1,0};
     34 const int y4[]={0,1,0,-1};
     35 const int x8[]={-1,-1,0,1,1,1,0,-1};
     36 const int y8[]={0,1,1,1,0,-1,-1,-1};
     37 ///////////////////////////////////////////////////////////////////////////
     38 
     39 ///////////////////////////////////////////////////////////////////////////
     40 typedef long long LL;
     41 
     42 typedef int T;
     43 T max(T a,T b){ return a>b? a:b; }
     44 T min(T a,T b){ return a<b? a:b; }
     45 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
     46 T lcm(T a,T b){ return a/gcd(a,b)*b; }
     47 ///////////////////////////////////////////////////////////////////////////
     48 
     49 ///////////////////////////////////////////////////////////////////////////
     50 //Add Code:
     51 ///////////////////////////////////////////////////////////////////////////
     52 
     53 int main(){
     54     ///////////////////////////////////////////////////////////////////////
     55     //Add Code:
     56     int n,a,b;
     57     while(scanf("%d",&n)!=EOF){
     58         bool is_stack=1,is_queue=1,is_priority_queue=1;
     59         stack<int> s;
     60         queue<int> q;
     61         priority_queue<int> pq;
     62         while(n--){
     63             scanf("%d%d",&a,&b);
     64             if(a==1){
     65                 if(is_stack) s.push(b);
     66                 if(is_queue) q.push(b);
     67                 if(is_priority_queue) pq.push(b);
     68             }
     69             else{
     70                 if(is_stack){
     71                     if(!s.empty() && s.top()==b) s.pop();
     72                     else is_stack=0;
     73                 }
     74                 if(is_queue){
     75                     if(!q.empty() && q.front()==b) q.pop();
     76                     else is_queue=0;
     77                 }
     78                  if(is_priority_queue){
     79                     if(!pq.empty() && pq.top()==b) pq.pop();
     80                     else is_priority_queue=0;
     81                 }
     82             }
     83         }
     84         int sum=(int)is_stack+(int)is_queue+(int)is_priority_queue;
     85         if(sum==0) printf("impossible
    ");
     86         else if(sum>=2) printf("not sure
    ");
     87         else{
     88             if(is_stack) printf("stack
    ");
     89             else if(is_queue) printf("queue
    ");
     90             else printf("priority queue
    ");
     91         }
     92     }
     93     ///////////////////////////////////////////////////////////////////////
     94     return 0;
     95 }
     96 
     97 ///////////////////////////////////////////////////////////////////////////
     98 /*
     99 Testcase:
    100 Input:
    101 6
    102 1 1
    103 1 2
    104 1 3
    105 2 1
    106 2 2
    107 2 3
    108 6
    109 1 1
    110 1 2
    111 1 3
    112 2 3
    113 2 2
    114 2 1
    115 2
    116 1 1
    117 2 2
    118 4
    119 1 2
    120 1 1
    121 2 1
    122 2 2
    123 7
    124 1 2
    125 1 5
    126 1 1
    127 1 3
    128 2 5
    129 1 4
    130 2 4
    131 Output:
    132 queue
    133 not sure
    134 impossible
    135 stack
    136 priority queue
    137 */
    138 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    jvm
    java8新特性Lambada,Steam流
    数组链表栈队列 散列表
    数据结构算法基本知识
    设计模式七大原则
    java关键字
    Excel导出(适合项目开发)
    Excel导出(适合初学者)
    angular.min.js:80 Error:
    angular中出现错误的提示指令[ng:areq]的原因
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3312635.html
Copyright © 2011-2022 走看看