zoukankan      html  css  js  c++  java
  • HDU 5818 Joint Stacks

    搞了第三个栈来表示合并之后的。偷懒写了一个优先队列。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    inline int read()
    {
        char c = getchar(); while(!isdigit(c)) c = getchar(); int x = 0;
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();  }
        return x;
    }
    
    const int maxn=100000+10;
    struct X
    {
        int f,num;
        X(int F,int Num)
        {
            f=F, num=Num;
        }
        bool operator < (const X &a) const {
            return f<a.f;
        }
    };
    
    priority_queue<X>Q;
    stack<X>s[3];
    int n,t;
    
    int main()
    {
        //File();
        int cas=1;
        while(~scanf("%d",&n))
        {
            if(n==0) break;
            printf("Case #%d:
    ",cas++);  t=1;
            while(!Q.empty()) Q.pop();
            while(!s[0].empty()) s[0].pop(); 
            while(!s[1].empty()) s[1].pop();
            for(int i=1; i<=n; i++)
            {
                char op[10];
                scanf("%s",op);
                if(strcmp("push",op)==0)
                {
                    scanf("%s",op);
                    if(op[0]=='A') { int x; scanf("%d",&x); s[0].push(X(t++,x)); }
                    else { int x; scanf("%d",&x); s[1].push(X(t++,x)); }
                }
                else if(strcmp("pop",op)==0)
                {
                    scanf("%s",op);
                    if(op[0]=='A')
                    {
                        if(!s[0].empty()) { printf("%d
    ",s[0].top().num); s[0].pop(); }
                        else { printf("%d
    ",Q.top().num); Q.pop(); }
                    }
                    else
                    {
                        if(!s[1].empty()) { printf("%d
    ",s[1].top().num); s[1].pop(); }
                        else { printf("%d
    ",Q.top().num); Q.pop(); }
                    }
                }
                else
                {
                    char s1[5],s2[5]; scanf("%s%s",s1,s2);
                    while(!s[0].empty()) { X h=s[0].top(); s[0].pop(); Q.push(h); }
                    while(!s[1].empty()) { X h=s[1].top(); s[1].pop(); Q.push(h); }
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    1.1.28 文字所在段落增加下划线
    Microsoft Project 2010基础使用方法
    16.3 将Win7文档的内容到复制Linux的vi中
    3.4 在Word中的公式和序号之间填充连续的点
    18.25 JLink调试程序步骤
    18.24 Ubuntu修改静态IP
    18.23 inline函数功能
    18.22 sprintf函数功能
    18.21 关键字extern
    18.20 频率单位转换
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5759063.html
Copyright © 2011-2022 走看看