zoukankan      html  css  js  c++  java
  • codeforces 420B Online Meeting

    一道实现很蛋疼的题。必须静下理清思路,整理出各种情况。不然就会痛苦地陷入一大堆if..else里不能自拔。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<iostream>
    #include<sstream>
    #include<cmath>
    #include<climits>
    #include<string>
    #include<map>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<set>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    #define pb(a) push(a)
    #define INF 0x1f1f1f1f
    #define lson idx<<1,l,mid
    #define rson idx<<1|1,mid+1,r
    #define PI  3.1415926535898
    template<class T> T min(const T& a,const T& b,const T& c) {
        return min(min(a,b),min(a,c));
    }
    template<class T> T max(const T& a,const T& b,const T& c) {
        return max(max(a,b),max(a,c));
    }
    void debug() {
    #ifdef ONLINE_JUDGE
    #else
    
        freopen("in.txt","r",stdin);
        freopen("d:\out1.txt","w",stdout);
    #endif
    }
    int getch() {
        int ch;
        while((ch=getchar())!=EOF) {
            if(ch!=' '&&ch!='
    ')return ch;
        }
        return EOF;
    }
    
    const int maxn = 1e5+5;
    bool canbe[maxn];
    int canbeset[maxn];
    int first[maxn];
    char op[maxn];
    int id[maxn];
    int main()
    {
        int n,m;
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= m; i++ )
        {
            op[i] = getch();
            scanf("%d", &id[i]);
            if( first[id[i]] == 0 )
                first[id[i]] = op[i] == '+' ? 1 : -1;
    
        }
        int cnt=0;
        int sz=0;
        for(int i=1;i<=n;i++)
        {
            if(first[i]==-1)
                cnt++;
            if(first[i]==1)
                canbeset[sz++]=i;
        }
    
        for(int i=1;i<=n;i++) canbe[i] = true;
        if(cnt>0) for(int i=1;i<=n;i++)
            if(first[i]==1) canbe[canbeset[--sz]] = false;
    
        for(int i=1;i<=m;i++)
        {
            if(op[i]=='+')
            {
                if(cnt>0) canbe[id[i]]=0;
                cnt++;
                while(sz)
                {
                    sz--;
                    if(canbeset[sz]!=id[i]) canbe[canbeset[sz]]=0;
                }
            }else
            {
                cnt--;
                if(cnt>0) canbe[id[i]]=0;
                if(canbe[id[i]]) canbeset[sz++]=id[i];
            }
        }
        sz=0;
        for(int i=1;i<=n;i++)
            if(canbe[i])
                canbeset[sz++]=i;
        printf("%d
    ",sz);
        for(int i=0;i<sz;i++)
            printf("%d%c",canbeset[i],i==sz-1?'
    ':' ');
    
        return 0;
    }
    View Code
  • 相关阅读:
    shell学习(4)- awk
    shell学习(3)- grep
    职场社交软件脉脉职言区最近一个星期在聊什么?
    shell学习(2)- sed
    shell学习(1)
    aws cli command line interface的安装与使用
    linux定时任务报错mysql: command not found
    如何做技术积累
    基于php的AWS存储服务
    机器学习:卷积神经网络
  • 原文地址:https://www.cnblogs.com/BMan/p/3687461.html
Copyright © 2011-2022 走看看