• Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟


    B. Berland National Library
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

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

    Description

    Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.

    Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned aregistration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:

    • "ri" — the reader with registration number ri entered the room;
    • "ri" — the reader with registration number ri left the room.

    The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.

    Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.

    Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

    Input

    The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "ri" or "ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).

    It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

    Output

    Print a single integer — the minimum possible capacity of the reading room.

    Sample Input

    6
    + 12001
    - 12001
    - 1
    - 1200
    + 1
    + 7

    Sample Output

    3

    HINT

    题意

    +表示进去了一个编号为x的人,-表示出去了一个编号为x的人,然后每个人会使用一个房间

    问你这个地方最少得有多少个房间

    题解

    模拟一下就好了,如果这个人出去的话,就会空出一个房间,那么下一个人进去就会占据这个房间

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    map<int,int> H;
    int main()
    {
        int n=read();
        int now=0;
        int tip=0;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            string s;
            cin>>s;
            int k=read();
            if(s[0]=='+')
            {
                if(tip>0)
                {
                    tip--;
                    H[k]=1;
                }
                else
                {
                    now++;
                    H[k]=1;
                }
            }
            else
            {
                if(H[k]==1)
                    H[k]=0,tip++;
                else
                    now++,tip++;
            }
            ans=max(ans,now);
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    HDU 1850 Being a Good Boy in Spring Festival
    UESTC 1080 空心矩阵
    HDU 2491 Priest John's Busiest Day
    UVALive 6181
    ZOJ 2674 Strange Limit
    UVA 12532 Interval Product
    UESTC 1237 质因子分解
    UESTC 1014 Shot
    xe5 android listbox的 TMetropolisUIListBoxItem
    xe5 android tts(Text To Speech)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4706303.html
Copyright © 2020-2023  润新知