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
  • 相关阅读:
    蓝牙模块连接后出现ANR,日志记录
    移动基站问题
    从地址栏获取字符串
    jquery升级换代
    手机屏幕的触点
    屏幕翻转后要干什么
    条件判断后吸住底部的总结
    mouseenter 和 mouseleave
    自动垂直居中的js
    数学方法代替浮动解决自动换行排列
  • 原文地址:https://www.cnblogs.com/BMan/p/3687461.html
Copyright © 2011-2022 走看看