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 ...
随机推荐
- 为啥RESTFULL如此重要?
为啥RESTFULL如此重要? 2014-6-3 20:13| 发布者: admin| 查看: 57| 评论: 0|来自: java365 摘要: 本文我们将讨论REST,它定义了一组体系架构原则,您 ...
- Cent OS 常用命令搜集
打开一个 Shadowsocks 配置文件nano /etc/shadowsocks.json 重启 Shadowsocks/etc/init.d/shadowsocks restart centos ...
- 启用PAE后虚拟地址到物理地址的转换
34 注册:2013-10 帖子:2013 精华:34 --> [原创]启用PAE后虚拟地址到物理地址的转换 安于此生 2013-11-3 20:54 16073 由常规的两级页表转换得不到 ...
- Objective-c官方文档 怎么使用对象
版权声明:原创作品,谢绝转载!否则将追究法律责任. 对象发送和接受消息 尽管有不同的方法来发送消息在对象之间,到目前位置是想中括号那样[obj doSomeThing]:左边是接受消息的接收器,右 ...
- 【数据处理】SQL Server高效大数据量存储方案SqlBulkCopy
要求将Excel数据,大批量的导入到数据库中,尽量少的访问数据库,高性能的对数据库进行存储. 一个比较好的解决方案,就是采用SqlBulkCopy来处理存储数据. SqlBulkCopy存储大批量的数 ...
- cxGrid数据录入
一.数据录入 1 在TcxGridDBTableView中,设定属性 NewItemRow.Visible = True 2 在cxgrid中输入数据怎样回车换行 在TcxGridDBTableV ...
- Excel中用countif和countifs统计符合条件的个数 good
countif单条件统计个数 1 就以下表为例,统计总分大于(包含等于)400的人数. 2 在J2单元格输入公式=COUNTIF(I2:I22,">=400") 3 回车 ...
- maven中properties标签定义变量
在pom.xml中添加依赖时语法如下 <dependency> <groupId>org.springframework</groupId> <artifac ...
- SpringMVC温故知新
1. SpringMVC流程简记 (1) 用户发送请求至前端控制器DispatcherServlet (2) DispatcherServlet收到请求调用HandlerMapping处理器映射器 ( ...
- 应该了解的Openstack命令
整理一下Openstack的命令.下面的命令,我都是全部在机器验证过,主要是参考 redhat文档 查看rabbitmq 队列 rabbitmqctl list_queues 查看keystone的用 ...