标签:codeforces round #pi berland national lib codeforces acm stl
思路:对于这道题,一开始并没有什么思路,但后来想了下,其实就是维护一个集合,每一个人都是不同的元素,满足了集合的互异性,而要求这个图书馆最小的容纳量,其实就是求这个集合的最大的元素量,假设在某个时刻集合里存在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;
}
版权声明:转载务必请标明出处,谢谢
Codeforces Round #Pi (Div. 2) B Berland National Library
标签:codeforces round #pi berland national lib codeforces acm stl
原文地址:http://blog.csdn.net/wyt734933289/article/details/47314397