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 题意:题目大意: 一个计数器, +号代表一个人进入图书馆, -号代表一个人出去图书馆. 给一个 ...
随机推荐
- iOS- UITableViewCell对象是怎么重用的 ?
iOS设备的内存有限,如果用UITableView显示成千上万条数据, 就需要成千上万个UITableViewCell对象的话, 那将会耗尽iOS设备的内存.要解决该问题,需要重用UITableVie ...
- linux 相关的问题
1,查找当前目录下的文件名,并重定向到文件t中 ls > t mac 下快速补全目录名快捷键tab
- 主流 Kubernetes 发行版梳理
2014 年,Kubernetes 作为内部 Google orchestrator Borg 开源版本推出,目前已是最成功和发展最快的 IT 基础架构项目之一.2018 年,Kubernetes 已 ...
- WPF 资源应用
对资源的应用,有好多方法,以下是一些应用,可以参考 1.静态资源: 2.动态资源: 3.项目面板中的资源: 4.图片.声音等资源
- .NET中SQL Server数据库连接方法
1. 使用本机上的SQL Server Express 实例上的用户实例. 用户实例的连接创建了一个新的SQL Server 实例.此连接只能是在本地SQL Server 2005实例上并 ...
- 7款很棒的 HTML5 视频播放器
做个连接:http://www.cnblogs.com/lhb25/archive/2011/06/27/7-great-html-5-video-player-scripts.html
- Luogu1092 NOIP2004虫食算(搜索+高斯消元)
暴力枚举每一位是否进位,然后就可以高斯消元解出方程了.然而复杂度是O(2nn3),相当不靠谱. 考虑优化.注意到某一位进位情况的变化只会影响到方程的常数项,于是可以在最开始做一次高斯消元算出每个未知数 ...
- CF997B Roman Digits
题意翻译 给你一棵树,每次挑选这棵树的两个叶子,加上他们之间的边数(距离),然后将其中一个点去掉,问你边数(距离)之和最大可以是多少. 题目描述 You are given an unweighted ...
- Oracle-RAC原理
Oracle-RAC原理 来源 https://blog.csdn.net/qq_34556414/article/details/79001267 单点数据库 VS RAC 单节点数据库,如果实例宕 ...
- 【以前的空间】bzoj [ZJOI2007]棋盘制作
具体可以去跪<浅谈用极大化思想解决最大子矩形问题>(p.s. 蒟蒻跪了还是很晕,不过想到之前usaco好像是最后一章的一道题……看了下代码顿然醒悟) 也就是如果用o(nm)的方法维护一个极 ...