zoukankan      html  css  js  c++  java
  • Berland National Library

    题目链接:http://codeforces.com/problemset/problem/567/B

    题目描述:

    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 a registration 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.

    Input:

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

    Output:

    3

    Input:

    2
    - 1
    - 2

    Output:

    2

    题目大意:告诉你n组记录,+ id表示id进入图书馆,-为id出图书馆,求图书馆最大容量(即某时刻图书馆内的人数最多)。注意,可能在你记录前就有人在里面了。

     1 #include <cstdio>
     2 #include <set>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int n,num,l,mx;  //l记录当前图书馆内的人数,mx维护最大容量
     8 char ch;
     9 
    10 set<int> s;
    11 
    12 int main(){
    13     while(~scanf("%d",&n)){
    14         l=0,mx=0;
    15         s.clear();
    16         set<int>::iterator it;
    17         for(int i=0;i<n;i++){
    18             getchar();
    19             scanf("%c %d",&ch,&num);
    20             if(ch=='+' ){
    21                 s.insert(num);
    22                 l++;
    23                 mx=max(l,mx);
    24             }
    25             else if(ch=='-'){
    26                 if(!s.count(num)){
    27                     mx++;
    28                 }
    29                 else{
    30                     l--;
    31                     it=s.find(num);
    32                     s.erase(it);
    33                 }
    34             }
    35         }
    36         printf("%d
    ",mx);
    37     }
    38 }
  • 相关阅读:
    基于redis实现rpc服务注册
    手写web服务器:实现简单filter逻辑
    手写controller、requestMapping注解,实现简单请求
    docker 制作自己的镜像
    MySqlConnector.MySqlException (0x80004005): Table '****' doesn't 解决方法
    在docker 容器中安装vim
    VM CentOS 安装Docker
    win 10的VM上安装centOS后的网络连接
    js数组方法大全
    Netcore使用Filter来实现接口的全局异常拦截
  • 原文地址:https://www.cnblogs.com/Dillonh/p/8709680.html
Copyright © 2011-2022 走看看