您的位置:首页 > 其它

构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

2015-08-06 21:10 513 查看
题目传送门

 /*
题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆
构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下
*/
/************************************************
* Author        :Running_Time
* Created Time  :2015-8-6 0:23:37
* File Name     :B.cpp
************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
bool in[MAXN];

int main(void)    {     //Codeforces Round #Pi (Div. 2) B. Berland National Library
int n;  scanf ("%d", &n);
memset (in, false, sizeof (in));
int now = 0, sz = 0;
for (int i=1; i<=n; ++i)    {
char s[2];    int x;  scanf ("%s%d", &s, &x);
if (s[0] == '+')  {
now++;  in[x] = true;
if (now > sz)   sz++;
}
else if (s[0] == '-')   {
if (now == 0)   {
if (in[x])  in[x] = false;
sz++;
}
else    {
if (!in[x]) {       //是之前就进入图书馆的读者
sz++;
}
else    {
in[x] = false;  now--;
}
}
}
}

printf ("%d\n", sz);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: