zoukankan      html  css  js  c++  java
  • Berland National Library codeforces 567B(模拟)

    http://codeforces.com/problemset/problem/567/B

    题意:图书馆有一个程序,可以记录学生的进出情况,'+'表示进入,'-'表示出去,字符后面的数字表示学生的编号。在这个程序尚未启动前,还有一些同学进的消息没有被记录下来。现在问你这个图书馆至少得容纳多少学生。

    分析:用sum和ans两个值来记录,sum存当前房间人数,ans维护最大值。

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    
    using namespace std;
    
    #define INF 0x3f3f3f3f
    const int maxn = 1e6+5;
    
    typedef long long LL;
    
    int v[maxn];
    
    int main()
    {
        int n, m, sum, ans;
        char ch[5];
    
        while(scanf("%d", &n)!=EOF)
        {
            memset(v, 0, sizeof(v));
            sum = ans = 0;
            
            ///sum存当前房间里有多少个人
            ///ans存房间至少有多少个人
            for(int i=0; i<n; i++)
            {
                scanf("%s%d", ch, &m);
                if(ch[0]=='+')
                {
                    v[m] ++;
                    sum ++;
                    ans = max(ans, sum);
                }
                else
                {
                    if(!v[m]) ans++;///若v[m]==0,则证明它是在图书馆系统未开放前进去的
                    else sum--;///若v[m]有值,则反之
                }
            }
    
            printf("%d
    ", ans);
    
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Python 包的概念
    EXCEL基础篇(二)
    EXCEL基础篇(一)
    JavaScript(四)Bom
    JavaScript(三)Dom查找、设置标签属性及内容、绑定事件
    erlang并发编程(二)
    OTP&ETS
    erlang中http请求
    erlang证书加密
    erlang并发编程
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5775271.html
Copyright © 2011-2022 走看看