CodeForces 567B Berland National Library
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
Input +
-
-
-
+
+
Output Input -
-
Output Input +
-
Output Hint
In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers , and . More people were not in the room at the same time based on the log. Therefore, the answer to the test is .
题目链接:http://codeforces.com/problemset/problem/567/B
********************************************
题意:给出一个图书馆人员进出情况,问图书馆满足题意的最小容量是多少。
分析:模拟题,开个数组标记状态。结果是有记录的最大值+没有记录只有'-'的人的数量。
AC代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<time.h>
using namespace std;
#define N 1000050 int a[N];
char s[N]; int main()
{
int n,i,x; while(scanf("%d", &n) != EOF)
{
memset(a,,sizeof(a)); int ans=;///记录人数变化
int maxx=;///储存最大人数
for(i=;i<n;i++)
{
scanf("%s %d", s,&x); if(s[]=='+')
{
a[x]=;///标记在图书馆里
ans++;
maxx=max(ans,maxx);
}
else
{
if(a[x])
ans--;
else
maxx++;
}
}
printf("%d\n", maxx);
}
return ;
}
CodeForces 567B Berland National Library的更多相关文章
- CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 #include<cstdio> #include<cstring ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 567B:Berland National Library(模拟)
time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...
- 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 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 ...
- Berland National Library
题目链接:http://codeforces.com/problemset/problem/567/B 题目描述: Berland National Library has recently been ...
- [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)
[Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ...
随机推荐
- shell 之awk 关联数组高级应用
最近由于数据迁移过,有些用户信息需要再次确认下,也许数据量比较大,但是需要最终确认的比如说是用户ID和其对应的用户积分数,这样就会导致出现文本a(老的数据),文本b(新的数据).比如 这是文本a.tx ...
- NOIP2011-普及组复赛模拟试题-第二题-买票
题目背景 Background Ztc真的遇上黄牛了... 题目描述 Description 周末Ztc想去剧场看演出,但是他没有票.这时,救世主Wzj出现了,他慷慨地愿意卖给Ztc一些票. ...
- iOS 时间戳的问题
- (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // 格式化时间 NSDateFormatter* formatte ...
- php 过滤emoji表情
function yz_expression() { foreach ($_POST as $key => &$value) { $value = preg_replace_callba ...
- php 验证码类
<?php class Vcode { private $width; //宽 private $height; //高 private $num; //数量 private ...
- 三、oracle 用户管理(user)
一.创建用户概述:在oracle中要创建一个新的用户使用create user语句,一般是具有dba(数据库管理员)的权限才能使用.create user 用户名 identified by 密码; ...
- test错误记录
1.Caused by: java.io.FileNotFoundException: D:\Program%20Files\Apache%20Software%20Foundation\Tomcat ...
- java学习第21天(IO流的使用)
IO流分类: A:流向 输入流 读取数据 输出流 写出数据 B:数据类型 字节流 字节输入流 字节输出流 字符流 字符输入流 字符输出流 注意: a:如果我们没有明确说明按照什么分,默认按照数据类型分 ...
- akka 入门
http://blog.csdn.net/thkhxm/article/details/40182835 1.首先安装akka的相关包-- http://akka.io/downloads/2.导入依 ...
- cmstop中实例化controller_admin_content类传递$this,其构造方法中接收到的是--名为cmstop的参数--包含cmstop中所有属性
主程序cmstop类,实例化controller_admin_content类(接收请求后拼接的).传递cmstop所有属性过去.controller_admin_content.构造方法中接收到名称 ...