zoukankan      html  css  js  c++  java
  • hdu 5071

    题意:  大模拟

    题解:每次把always top标记的人关掉要把标记也去掉,聊天数用long long,最后先和有标记的人说拜拜

    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <stack>
    #include <cmath>
    //#pragma comment(linker, "/STACK:102400000,102400000")
    using namespace std;
    #define PF(x) cout << "debug: " << x << " ";
    #define EL cout << endl;
    #define PC(x) puts(x);
    typedef long long ll;
    #define CLR(x, v) sizeof (x, v, sizeof(x))
    using namespace std;
    const int INF = 0x5f5f5f5f;
    const int  N= 2e5 + 10;
    const int mod=1e9 + 7;
    const int maxn = 5e3 + 10;
    int n,t,topfg,stk[maxn],cnt;//num shuohua  shuliang,fg  shifou  zai duilie
    map<int,ll>fg,num;
    int main()
    {
      // freopen("in.txt","r",stdin);
        cin>>t;
        int cas = 0;
        while(t--){
            fg.clear();
            num.clear();
            topfg = 0;
            cnt = 0;
            cas = 0;
            scanf("%d",&n);
            char ss[20];
            while(n--){
                cas++;
                printf("Operation #%d: ",cas);
                getchar();
                scanf("%s",ss);
               // cout<<ss<<endl;
                if(ss[0]=='A'){
                    int u;
                    scanf("%d",&u);
                   if(fg[u] > 0) printf("same priority.
    ");
                    else{
                        stk[++cnt] = u;
                        fg[u] = 1;
                        printf("success.
    ");
                    }
                }
                else if(ss[0] == 'R'){
                    int u;
                    scanf("%d",&u);
                    if(u < 1||u > cnt)
                        printf("out of range.
    ");
                    else{
                        int x = stk[u];
                        for(int i = u;i >= 2;i--)
                            stk[i] = stk[i - 1];
                        stk[1] = x;
                        printf("success.
    ");
                    }
                }
                else if(ss[0] == 'P'){
                    if(cnt == 0) printf("empty.
    ");
                    else{
                        int pos;
                        int pir = 0;
                        for(int i = 1;i <= cnt;i++){
                            if(pir < stk[i]){
                                pos = i;
                                pir = stk[i];
                            }
                        }
                        for(int i = pos;i >= 2;i--)
                            stk[i] = stk[i - 1];
                        stk[1] = pir;
                        printf("success.
    ");
                    }
                }
                else if(ss[0] == 'T'){
                    int u;
                    scanf("%d",&u);
                    if(!fg[u])  printf("invalid priority.
    ");
                    else{
                        topfg = u;
                        printf("success.
    ");
                    }
                }
                else if(ss[0] == 'U'){
                    if(topfg == 0) printf("no such person.
    ");
                    else {
                    topfg = 0;
                    printf("success.
    ");
                }
                }
                else if(ss[0] == 'C'){
                    if(ss[1] == 'l'){
                        int u;
                        scanf("%d",&u);
                        if(!fg[u])  printf("invalid priority.
    ");
                        else{
                            printf("close %d with %lld.
    ",u,num[u]);
                            if(topfg == u) topfg = 0;
                            num[u] = 0,fg[u] = 0;
                            
                            int pos = 0;
                            for(int i = 1;i <= cnt;i++){
                                if(stk[i] == u){
                                    pos = 1;
                                    continue;
                                }
                                if(pos)
                                    stk[i - 1] = stk[i];
                            }
                            cnt--;
                           // printf("success.
    ");
                        }
    
                    }
                    if(ss[1] == 'h'){
                        if(ss[2] == 'a'){
                        int w;
                        scanf("%d",&w);
                        if(cnt == 0) printf("empty.
    ");
                        else{
                            if(topfg > 0 && fg[topfg] > 0) num[topfg] += w;
                            else num[stk[1]] += w;
                            printf("success.
    ");
                        }
                    }
                        if(ss[2] == 'o'){
                            int u;
                            scanf("%d",&u);
                            if(!fg[u]) printf("invalid priority.
    ");
                            else{
                                int pos;
                                int pir = u;
                                for(int i = 1;i <= cnt;i++){
                                    if(u == stk[i]){
                                        pos = i;
                                        break;
                            }
                        }
                                for(int i = pos;i >= 2;i--)
                                    stk[i] = stk[i - 1];
                                stk[1] = pir;
                                printf("success.
    ");
    
                            }
    
                        }
    
                   }
                }
    
            }
           if(fg[topfg] > 0&& num[topfg] > 0)  printf("Bye %d: %lld
    ",topfg,num[topfg]);
           num[topfg] = 0;
            for(int i = 1;i <= cnt;i++)
                if(num[stk[i]] > 0&&fg[stk[i]] > 0)
                    printf("Bye %d: %lld
    ",stk[i],num[stk[i]]);
    
        }
    
        return 0;
    }
  • 相关阅读:
    uva11572 Unique Snowflakes
    codeforces#333 div2 B. Approximating a Constant Range
    uva11134 Fabled Rooks
    吐槽。。。
    uva 1605 Building for UN
    uva 120 Stacks of Flapjacks
    uva1152 4 Values whose Sum is 0
    uva817 According to Bartjens
    uva11214 Guarding the Chessboard
    无标题
  • 原文地址:https://www.cnblogs.com/shimu/p/5826945.html
Copyright © 2011-2022 走看看