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 ...
随机推荐
- RAC的搭建(二)--创建ASM磁盘
1. 规划 表决磁盘: 1Gx3(3节点以下,建议都采用这种配置,三个磁盘加起来要大于1.8G,否则会报错) 数据磁盘: 10Gx1 闪回磁盘: 5Gx1 2. 创建共享磁盘 virtualBox上 ...
- Vim 手记:语法高亮
本文覆盖范围: Vim 的着色方案 设置高亮 选择颜色 语法高亮除错 每个程序员的文本编辑器缺少了语法高亮.特殊关键字和短语着色,都是不完整的.语法高亮突出了文档的结构,帮助发现排字错误,利于调试,整 ...
- 第四篇:MapReduce计算模型
前言 本文讲解Hadoop中的编程及计算模型MapReduce,并将给出在MapReduce模型下编程的基本套路. 模型架构 在Hadoop中,用于执行计算任务(MapReduce任务)的机器有两个角 ...
- mysql5.6.34-debug Source distribution在树莓派下编译的几个错误
raspberrypi下编译mysql5.6 debug版源码. 1. 启动错误 和mysqld相关的文件及文件夹权限必须设置为mysql用户可读可写可执行,特别是/var/run/mysqld/目录 ...
- Matlab 二维绘图函数(plot类)
plot 功能 绘制二维图形的最基本函数. 语法 //x为向量时,以x的元素值为纵坐标,x的序号为横坐标绘制曲线. //x为矩阵时,以其序号为横坐标,按列绘制每列元素值相对于其序号的曲线. polt( ...
- 《转》Python学习(13)-Python的字符编码
转自 http://www.cnblogs.com/BeginMan/p/3166363.html 一.字符编码中ASCII.Unicode和UTF-8的区别 点击阅读:http://www.cnbl ...
- 【技术分享会】 @第七期 android开发基础
前言 Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发. Android 软件系列包括操作系统.中间 ...
- css3整理--gradient
gradient语法: -moz-linear-gradient( [<point> || <angle>,]? <stop>, <stop> [, & ...
- Android与互联网的交互方式有三种
数据下载:下载网络上的的数据,包括图片.代码文本.XML文件.JSON数据,音/视频等大文件,调用webservice. 数据上传:上传图片.文本.XML.JSON数据.音/视频文件,调用webser ...
- Android 全屏Activity以透明的对话框形式弹出
1. styles.xml <style name="transcutestyle" parent="@android:style/Theme.DeviceDefa ...