B. Berland National Library---cf567B(set|模拟)
题目链接:http://codeforces.com/problemset/problem/567/B
题意:题目大意: 一个计数器, +号代表一个人进入图书馆, -号代表一个人出去图书馆. 给一个log, 问这个log中能知道的这个图书馆最小的可能容量是多少, log是片段, 在program运行前可能图书馆已经有人, 在运行后也
可能人还没出去?
方法一:模拟;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <string>
using namespace std;
#define N 1000005
#define INF 0x3f3f3f3f
#define met(a, b) memset(a, b, sizeof(a))
typedef long long LL; int n, a[N], b[N]; char s[N][];
int main()
{
while(scanf("%d", &n) != EOF)
{
met(a, );
met(b, ); int ans = ; for(int i=; i<n; i++)
{
scanf("%s %d", s[i], &a[i]);
if(s[i][] == '+')
b[a[i]] = ;
else if(b[a[i]] == )
ans ++;///先求出原本里面有多少人;
} int Max = ans;
for(int i=; i<n; i++)
{
if(s[i][] == '+')
ans ++;
else
ans--;
Max = max(Max, ans);///再统计过程中的流通人量;
}
printf("%d\n", Max);
}
return ;
}
方法二:STL
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <string>
#include <set>
using namespace std;
#define N 1000005
#define INF 0x3f3f3f3f
#define met(a, b) memset(a, b, sizeof(a))
typedef long long LL; int main()
{
int n;
while(~scanf("%d", &n))
{
set<int>s;
int ans = ;
for(int i=; i<=n; i++)
{
char ch[]; int num;
scanf("%s %d", ch, &num);
if(ch[] == '-' && s.find(num) == s.end() )
ans++;
else if(ch[] == '-' && s.find(num)!=s.end() )
s.erase(num);
else
{
s.insert(num);
int len = s.size();
ans = max(ans, len);
}
}
printf("%d\n", ans);
}
return ;
}
B. Berland National Library---cf567B(set|模拟)的更多相关文章
- 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 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 567B Berland National Library
Description Berland National Library has recently been built in the capital of Berland. In addition, ...
- Codeforces B - Berland National Library
B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...
- Berland National Library
题目链接:http://codeforces.com/problemset/problem/567/B 题目描述: Berland National Library has recently been ...
- 构造 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 ...
- CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 #include<cstdio> #include<cstring ...
随机推荐
- Linux应急响应入侵排查思路
0x00 前言 当企业发生黑客入侵.系统崩溃或其它影响业务正常运行的安全事件时,急需第一时间进行处理,使企业的网络信息系统在最短时间内恢复正常工作,进一步查找入侵来源,还原入侵事故过程,同时给出解 ...
- java.security.NoSuchAlgorithmException: SHA1PRNG SecureRandom not available
好久没有使用MyEclipse10了,今天打开看了以前大学的项目,在Tomcat7中发布启动,我嚓嘞,报错: SEVERE: Exception initializing random number ...
- ASP.NET MVC4优化
删除无用的视图引擎 默认情况下,ASP.NET MVCE同时支持WebForm和Razor引擎,而我们通常在同一个项目中只用到了一种视图引擎,如Razor,那么,我们就可以移除掉没有使用的视图引擎,提 ...
- linux 开机自启
cd /home/dpf 1.vi startup.sh #!/bin/shecho "hello world" >> /home/dpf/test.txt vi mq ...
- 实现iOS中的链式编程
谈到链式编程,那Masonry几乎就是最经典的代表.如: make.top.equalTo(self.view).offset() 像这样top.equalTo(self.view).offset(6 ...
- 音频中PCM的概念
本文取自由http://blog.csdn.net/droidphone一部分 1. PCM是什么 PCM是英文Pulse-code modulation的缩写,中文译名是脉冲编码调制.我们知道在现实 ...
- Java并发编程--BlockingQueue
概述 BlockingQueue支持两个附加操作的Queue:1)当Queue为空时,获取元素线程被阻塞直到Queue变为非空:2)当Queue满时,添加元素线程被阻塞直到Queue不满.Blocki ...
- 题目1208:10进制 VS 2进制(进制转换以及大数保存问题)
题目链接:http://ac.jobdu.com/problem.php?pid=1208 详细链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 题目1003:A+B(按逗号分隔的A+B)
题目链接:http://ac.jobdu.com/problem.php?pid=1003 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- Linux 帐户管理
一 用户相关操作 1. 添加帐户 useradd 选项 用户名 -c comment 指定一段注释性描述. -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录. -g 用 ...