Codeforces Round #Pi (Div. 2) B. Berland National Library set
2015-08-06 03:29
447 查看
B. Berland National Library
Time Limit: 2 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/567/problem/B
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 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 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.
Sample Input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
Sample Output
3
HINT
题意
+ 进入的编号
- 出去的编号
最多人的时候是几个人
题解:
set模拟
代码
Time Limit: 2 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/567/problem/B
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 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 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.
Sample Input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
Sample Output
3
HINT
题意
+ 进入的编号
- 出去的编号
最多人的时候是几个人
题解:
set模拟
代码
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <queue> #include <typeinfo> #include <map> #include <stack> typedef __int64 ll; #define inf 0x7fffffff using namespace std; inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //************************************************************************************** set<int > s; set<int >::iterator it,itt; int main() { char ch; int m; int n=read(); int ans=0; for(int i=1;i<=n;i++) { scanf("%c %d",&ch,&m); if(ch=='-'){ if(s.count(m)) s.erase(m); else ans++; } else { s.insert(m); int j=s.size(); ans=max(j,ans); } getchar(); } cout<<ans<<endl; return 0; }
相关文章推荐
- 校园网锐捷Ubuntu12.04LTS
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水
- Ubuntu12.04LTS 使用锐捷上网 2012年
- C++ 中输出精度问题
- Codeforces Round #Pi (Div. 2) E. President and Roads tarjan+最短路
- sssssad
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解
- Codeforces Round #Pi (Div. 2) C. Geometric Progression map
- 最简单圆形图片和头像(重新封装ImageLoad)-巧用universal-image-loader
- Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水题
- cf #314 B. Berland National Library
- 利用github搭建个人maven仓库
- cf #314 A. Lineland Mail
- LeetCode 3Sum Closest
- LeetCode 3Sum Closest
- [LeetCode.Trick]Majority Element||
- _DataStructure_C_Impl:堆串
- _DataStructure_C_Impl:顺序串
- _DataStructure_C_Impl:双端队列