CodeForces 567B Berland National Library(模拟)(简单)

B. Berland National Library

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 from1 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 test(s)

input

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

output

3

input

2
- 1
- 2

output

2

input

2
+ 1
- 1

output

1

代码:

#include<iostream>
#include<set>
#include<cstdio>
using namespace std;

int main()
{
    set<int> s;
    int num=0;
    char c;int k,n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>c>>k;
        if(c=='+')
        {
            s.insert(k);
            int l=s.size();
            num=max(l,num);
        }
        else
        {
            if(s.find(k)==s.end())
                num++;
            else
                s.erase(k);
            int l=s.size();
            num=max(l,num);
        }
    }
    cout<<num<<endl;
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-22 08:52:24

CodeForces 567B Berland National Library(模拟)(简单)的相关文章

CodeForces 567B Berland National Library

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

CodeForces 567B Berland National Library hdu

这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 1 #include<cstdio> 2 #include<cstring> 3 4 const int HASH=57; 5 6 int n,num[110],head[HASH],next[110]; 7 8 void insert(int s) 9 { 10 int h=num[s]%HASH; 11 int u=head[h]; 12 while(u) u=n

Codeforces-B. Berland National Library(模拟)

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 roo

构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

题目传送门 1 /* 2 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 3 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 0:23:37 8 * File Name :B.cpp 9

Codeforces Round #Pi (Div. 2)——set——Berland National Library

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 roo

D - Berland National Library

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 roo

Berland National Library codeforces 567B(模拟)

http://codeforces.com/problemset/problem/567/B 题意:图书馆有一个程序,可以记录学生的进出情况,'+'表示进入,'-'表示出去,字符后面的数字表示学生的编号.在这个程序尚未启动前,还有一些同学进的消息没有被记录下来.现在问你这个图书馆至少得容纳多少学生. 分析:用sum和ans两个值来记录,sum存当前房间人数,ans维护最大值. #include <iostream> #include <stdio.h> #include <s

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

思路:对于这道题,一开始并没有什么思路,但后来想了下,其实就是维护一个集合,每一个人都是不同的元素,满足了集合的互异性,而要求这个图书馆最小的容纳量,其实就是求这个集合的最大的元素量,假设在某个时刻集合里存在M个元素,是集合从开始到结束出现过的元素个数的最大值,那么就是这个图书馆的最小容纳量,如果最小容纳量比M小,那怎么容得下M个人?对于+,   他之前肯定是没进或者之前出来股,无论怎样,都要加进集合. 对于一个集合的操作,在cf种时间为上的比赛,自然选用stl的set,如果各位有更好的思路或实

Codeforces Round #Pi (Div. 2) ——B. Berland National Library

这道题我一开始想了很久,但是fst 了.而且赛后想的也不是很清楚,所以有必要把它单独分出来讲清楚. 题意: 现在在log中有n条记录.然后每一条记录都写成:"+ri"或是"-ri"的形式.(其中+是代表有人进入,-代表有人出去)ri代表的是进入人的号码. 然后问你房间中最多同时有几个人存在. 思路: 我们需要两个变量max与sum,其中max是记录房间的最大容量的,sum是表示当前还有多少空位. 1)如果一个人进来了,如果当前没有空位的话,那么就max++,使房间容