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

    思路

    简单题,用栈,队列,优先队列直接模拟即可

    代码

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    #include <stack>
    using namespace std;
    queue<int> q;
    stack<int> S;
    priority_queue<int> pq;
    int n;
    int main(){
        while(scanf("%d",&n)==1){
            while(!q.empty())
                q.pop();
            while(!S.empty())
                S.pop();
            while(!pq.empty())
                pq.pop();
            bool isS=true,isq=true,ispq=true;
            for(int i=1;i<=n;i++){
                int opt,x;
                scanf("%d %d",&opt,&x);
                if(opt==1){
                    q.push(x);
                    pq.push(x);
                    S.push(x);
                }
                else{
                    if(q.empty())
                        isq=false;
                    if(pq.empty())
                        ispq=false;
                    if(S.empty())
                        isS=false;
                    if(isq){
                        int t=q.front();
                        if(t!=x)
                            isq=false;
                        q.pop();
                    }
                    if(ispq){
                        int t=pq.top();
                        if(t!=x)
                            ispq=false;
                        pq.pop();
                    }
                    if(isS){
                        int t=S.top();
                        if(t!=x)
                            isS=false;
                        S.pop();
                    }
                }
            }
            if((!ispq)&&(!isq)&&(!isS))
                printf("impossible
    ");
            else if((ispq)&&(!isq)&&(!isS))
                printf("priority queue
    ");
            else if((!ispq)&&(isq)&&(!isS))
                printf("queue
    ");
            else if((!ispq)&&(!isq)&&(isS))
                printf("stack
    ");
            else
                printf("not sure
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    SCCM2012 R2实战系列之四:初始化配置
    SCCM 2012 R2实战系列之一:SQL安装
    hdu 1242(bfs)
    hdu 1728(bfs)
    hdu 1253(bfs)
    hdu 3661
    hdu 1072(bfs)
    AC模版
    hdu 1010(dfs)
    poj 3628(01_page, dfs)
  • 原文地址:https://www.cnblogs.com/dreagonm/p/10681208.html
Copyright © 2011-2022 走看看