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.
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.
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出图书馆,求图书馆最大容量(即某时刻图书馆内的人数最多)。注意,可能在你记录前就有人在里面了。
#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
using namespace std; int n,num,l,mx; //l记录当前图书馆内的人数,mx维护最大容量
char ch; set<int> s; int main(){
while(~scanf("%d",&n)){
l=,mx=;
s.clear();
set<int>::iterator it;
for(int i=;i<n;i++){
getchar();
scanf("%c %d",&ch,&num);
if(ch=='+' ){
s.insert(num);
l++;
mx=max(l,mx);
}
else if(ch=='-'){
if(!s.count(num)){
mx++;
}
else{
l--;
it=s.find(num);
s.erase(it);
}
}
}
printf("%d\n",mx);
}
}
Berland National Library的更多相关文章
- Codeforces Round #Pi (Div. 2) B. Berland National Library set
B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- CodeForces 567B Berland National Library
Description Berland National Library has recently been built in the capital of Berland. In addition, ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #Pi (Div. 2) B Berland National Library
B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...
- Codeforces 567B:Berland National Library(模拟)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 #include<cstdio> #include<cstring ...
- B. Berland National Library---cf567B(set|模拟)
题目链接:http://codeforces.com/problemset/problem/567/B 题意:题目大意: 一个计数器, +号代表一个人进入图书馆, -号代表一个人出去图书馆. 给一个 ...
随机推荐
- TCP系列29—窗口管理&流控—3、Nagle算法
一.Nagle算法概述 之前我们介绍过,有一些交互式应用会传递大量的小包(称呼为tinygrams),这些小包的负载可能只有几个bytes,但是TCP和IP的基本头就有40bytes,如果大量传递这种 ...
- 3dContactPointAnnotationTool开发日志(十二)
因为ReferenceImage的锚点是固定的左下角,缩放时controller面板也会跟着动.为了使Scale的时候controller上的slider不会远离指针,于是把controller固 ...
- 多个表单数据提交下的serialize()应用
在实际开发场景中,难免遇到需要多个表单的数据传递问题. 之所以要进行多表单的数据传递是因为可以进行数据分组,便于数据的维护. 这个时候,出于不依赖jquery的考虑,有一个原生js函数来解决这个问题无 ...
- KindEditor是一套很方便的html编译器插件
KindEditor是一套很方便的html编译器插件.在这里做一个简单的使用介绍. 首先在官网上下载最新的KindEditor文件(里面有jsp,asp等不同版本文件夹,可以删掉你不需要的版本), 把 ...
- do_group_exit函数
一个进程在sleep状态如何获取进程的调用栈 TASK_WAKEUPKILL状态 一个进程sleep了,我如何获取他的用户态栈,如何获取用户堆栈 如何在内核态打印用户态+内核态的栈? 确定上一个调用栈 ...
- delphi 取得数据集某字段值的六种方法
//取name字段的示例 edit1.Text:=ADOquery1.Fields[2].AsString; //取得数据表的第二个字段的值 edit2.Text:=ADOquery1.Fie ...
- opencv 和 parfor
一次遇到两个不熟悉的,因此在一起记一下. OpenCV的全称是:Open Source Computer Vision Library. OpenCv是一个基于(开源)发行的跨平台计算机视觉库,可以运 ...
- BZOJ 2333 棘手的操作(离线+线段树+带权并查集)
这题搞了我一天啊...拍不出错原来是因为极限数据就RE了啊,竟然返回WA啊.我的线段树要开8倍才能过啊... 首先可以发现除了那个加边操作,其他的操作有点像线段树啊.如果我们把每次询问的联通块都放在一 ...
- 用select模拟一个socket server成型版2
1.字典队列测试 import queue msg_dic={} msg_dic[1]=queue.Queue() msg_dic[1].put('hello') msg_dic[1].put('bo ...
- POJ3070:Fibonacci——题解
http://poj.org/problem?id=3070 题目大意:求Fibonacci数列第n项,对10000取模. 矩阵乘法板子题……实在不知道写什么了. #include<iostre ...