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 }
  • 相关阅读:
    为啥我百度定位wifi可以定位准确,但用数据流量就给我定位到非洲西海岸
    利用BottomNavigationBar实现不同的fragment之间的转换
    VS2010中连接sql 2005连接问题microsoft.sqlserver.management.sdk.sfc
    zuul路由网关介绍及使用
    Hystrix断路器概述及使用
    Ribbon负载均衡概述及使用
    Eureka服务注册与发现 介绍及使用
    微服务介绍及springcloud入门概述
    springboot整合springdatajpa步骤及使用
    springboot整合shiro步骤
  • 原文地址:https://www.cnblogs.com/Dillonh/p/8709680.html
Copyright © 2011-2022 走看看