Codeforces Round #Pi (Div. 2) B Berland National Library
来源:互联网 发布:马云谈网络暴力 编辑:程序博客网 时间:2024/06/05 22:34
思路:对于这道题,一开始并没有什么思路,但后来想了下,其实就是维护一个集合,每一个人都是不同的元素,满足了集合的互异性,而要求这个图书馆最小的容纳量,其实就是求这个集合的最大的元素量,假设在某个时刻集合里存在M个元素,是集合从开始到结束出现过的元素个数的最大值,那么就是这个图书馆的最小容纳量,如果最小容纳量比M小,那怎么容得下M个人?对于+, 他之前肯定是没进或者之前出来股,无论怎样,都要加进集合。
对于一个集合的操作,在cf种时间为上的比赛,自然选用stl的set,如果各位有更好的思路或实现方法,一定要指教我
题目链接:http://codeforces.com/problemset/problem/567/B
#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<set>using namespace std;int main(void){ int n; while(~scanf("%d",&n)) { set<int> s; int ans=0; for(int i=0;i<n;i++) { getchar(); char ch;int num; scanf("%c",&ch); scanf("%d",&num); if(ch=='+') { s.insert(num); int d=s.size(); ans=max(d,ans); } else { if(s.find(num)==s.end()) ans++; else s.erase(num); int d=s.size(); ans=max(d,ans); } } printf("%d\n",ans); } return 0;}
1 0
- Codeforces Round #Pi (Div. 2) B. Berland National Library
- B. Berland National Library-水题- Codeforces Round #Pi (Div. 2)
- Codeforces Round #Pi (Div. 2) B Berland National Library
- Codeforces Round #Pi (Div. 2) B Berland National Library
- Codeforces Round #Pi (Div. 2)567B Berland National Library(模拟)
- Codeforces Round #Pi (Div. 2) B. Berland National Library (模拟)
- Codeforces Round #Pi (Div. 2) ——B. Berland National Library
- Codeforces B - Berland National Library
- Codeforces 567B Berland National Library
- Codeforces 567 B. Berland National Library
- CodeForces 567B Berland National Library
- CodeForces 567B Berland National Library
- CodeForces 567B Berland National Library
- CodeForces - 567B Berland National Library
- CodeForces-567B Berland National Library
- CodeForces 567B-Berland National Library
- CodeForces 567B Berland National Library
- Berland National Library CodeForces - 567B
- Windows10 如何会成为微软的新起点?
- Android应用分类
- form表单的提交方式总结
- Windows10 如何会成为微软的新起点?
- ISIS+BGP
- Codeforces Round #Pi (Div. 2) B Berland National Library
- java中的基本类型
- linux生成jar包,并运行,引用该jar包
- Windows10 如何会成为微软的新起点?
- Windows10 如何会成为微软的新起点?
- 杭电 1241 Oil Deposits 递归 DFS
- Spring使用SLF4J代替Commons Logging写日志
- [LeetCode] Distinct Subsequences
- POJ 3061 简单二分