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 ...
随机推荐
- MySQL on Linux 部署手册
1. 背景 MySQL为开源数据库,因此可以基于源码实现安装.基于源码安装有更多的灵活性.也就是说我们可以针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码,根据不同的软件平台环境调整相关的编 ...
- 【内网渗透笔记】Windows2008 R2搭建域控制器
0x00 前言 将网络中的多台计算机逻辑上组织到一起,进行集中管理,这种区别于工作组的逻辑环境叫做域(domain).域是日常计算机管理的一种很有效手段,因此,域控制器自然而然就在成域环境中最重要的角 ...
- RF判断列表、字典、整数、字符串类型是否相同方法
${d} create list shk shsh${w} create list ${e} evaluate type(${d}) ${t} evaluate type(${w}) should ...
- IIS URL Rewrite – Installation and Use
IIS URL Rewrite – Installation and Use Posted by Nick LeFevre | Leave a reply IIS URL Rewrite Instal ...
- mssql注入指令
and exists (select * from sysobjects) //判断是否是MSSQL and exists(select * from tableName) //判断某表是否存在..t ...
- Nginx SSL配置
一.SSL 原理 ① 客户端( 浏览器 )发送一个 https 请求给服务器② 服务器要有一套证书,其实就是公钥和私钥,这套证书可以自己生成,也可以向组织申请,服务器会把公钥传输给客户端③ 客户端收到 ...
- 网站前端性能优化之javascript和css
之前看过Yahoo团队写的一篇关于网站性能优化的文章,文章是2010年左右写的,虽然有点老,但是很多方面还是很有借鉴意义的.关于css的性能优化,他提到了如下几点: CSS性能优化 1.把样式表置于顶 ...
- 从PC端(Ubuntu)挂载nfs网络文件系统ARM9+Linux板子上
挂载概念 在windows操作系统中,挂载通常是指给磁盘分区(包括被虚拟出来的磁盘分区)分配一个盘符. 在linux操作系统中,它指将一个设备(通常是存储设备)挂接到一个已存在的目录上.(这个目录可以 ...
- 【面试题】源石智影科技Python工程师笔试题
哈哈 上图
- 【cs229-Lecture5】生成学习算法:1)高斯判别分析(GDA);2)朴素贝叶斯(NB)
参考: cs229讲义 机器学习(一):生成学习算法Generative Learning algorithms:http://www.cnblogs.com/zjgtan/archive/2013/ ...