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
  • 相关阅读:
    hdu 3790 最短路径问题
    hdu 2112 HDU Today
    最短路问题 以hdu1874为例
    hdu 1690 Bus System Floyd
    hdu 2066 一个人的旅行
    hdu 2680 Choose the best route
    hdu 1596 find the safest road
    hdu 1869 六度分离
    hdu 3339 In Action
    序列化和反序列化
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5775271.html
Copyright © 2011-2022 走看看