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 ...
随机推荐
- hadoop核心逻辑shuffle代码分析-map端
首先要推荐一下:http://www.alidata.org/archives/1470 阿里的大牛在上面的文章中比较详细的介绍了shuffle过程中mapper和reduce的每个过程,强烈推荐先读 ...
- CentoOS6.6安装netcat
http://blog.csdn.net/u013673976/article/details/47084841 CentOS下安装netcat 使用zookeeper过程中,需要监控集群状态.在使用 ...
- STL——配接器(adapters)
一.配接器 <Design Patterns>一书提到23个最普及的设计模式,其中对adapter样式的定义如下:将一个class的接口转换为另一个class 的接口,使原本因接口不兼容而 ...
- 深入浅出MFC——MFC骨干程序(四)
1. 熟记MFC类层次结构: 2. AppWizard可以为我们制作出MFC程序骨干: 3. Document/View支撑你的应用程序:Document/View的价值在于,这些MFC类已经把一个应 ...
- 为JDK自带的jvisualvm安装Visual GC插件
1.打开cmd,输入jvisualvm,回车: 2.点击工具——>插件; 3.访问网址:https://visualvm.github.io/pluginscenters.html,找到自己JD ...
- Linux IPC BSD Pipe
mkfifo() //创建有名管道(FIFO special file),创建完了就像普通文件一样open(),再读写,成功返回0,失败返回-1设errno.VS$man 3 mkfifo #incl ...
- 【python问题】UnicodeEncodeError: 'ascii' codec can't encode characters in position 306-309: ordinal not in range(128)
今天在写python爬虫的时候,遇到一个问题 UnicodeEncodeError: 'ascii' codec can't encode characters in position 306-309 ...
- C# 中对COOKIES的操作
HttpUtility.UrlDecode HttpUtility.UrlEncode HttpContext.Current.Request.Cookies["UserCode" ...
- Git 多人协作开发的过程
Git可以完成两件事情: 1. 版本控制 2.多人协作开发 如今的项目,规模越来越大,功能越来越多,需要有一个团队进行开发. 如果有多个开发人员共同开发一个项目,如何进行协作的呢. Git提供了一个非 ...
- goldengate 过滤对某张表的复制操作
在复制进程中配置下面的参数可以实现对一个用户下的某些表进行过滤,在复制的时候 不做任何操作. MAPEXCLUDE: Valid for Replicat Use the MAPEXCLUDE par ...