构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
/*
题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆
构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-6 0:23:37
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
bool in[MAXN]; int main(void) { //Codeforces Round #Pi (Div. 2) B. Berland National Library
int n; scanf ("%d", &n);
memset (in, false, sizeof (in));
int now = , sz = ;
for (int i=; i<=n; ++i) {
char s[]; int x; scanf ("%s%d", &s, &x);
if (s[] == '+') {
now++; in[x] = true;
if (now > sz) sz++;
}
else if (s[] == '-') {
if (now == ) {
if (in[x]) in[x] = false;
sz++;
}
else {
if (!in[x]) { //是之前就进入图书馆的读者
sz++;
}
else {
in[x] = false; now--;
}
}
}
} printf ("%d\n", sz); return ;
}
构造 Codeforces Round #Pi (Div. 2) B. Berland National Library的更多相关文章
- 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 Round #Pi (Div. 2) B. Berland National Library 模拟
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #Pi (Div. 2) B Berland National Library
B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
随机推荐
- JPA中映射关系详细说明(一对多,多对一,一对一、多对多)、@JoinColumn、mappedBy说明
JPA中的映射关系 jpa中维护one to one ,one to many, many to one ,many to many 四种映射关系. 在每个关系中,双方中的一方在其表中拥有连接列.那么 ...
- memcache 原理 & 监测 & 查看状态 & stats & 结构
Mencache内存存储方式:slab/LRU,采用预先申请固定大小的内存页(slab/page),然后再把内存分成多个块(chunk) 先放一张从网上找到的memcache内存结构图,觉得非常的赞:
- poj_3006_Dirichlet's Theorem on Arithmetic Progressions_201407041030
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Layui导航、面包屑
物不在多,有用则精! 学习使用链接 导航:导航一般指页面引导性频道集合,多以菜单的形式呈现,可应用于头部和侧边,是整个网页画龙点晴般的存在.面包屑结构简单,支持自定义分隔符.千万不要忘了加载 elem ...
- Servlet开发(1)
Servlet开发 Servlet引入: 百度百科详细servlet介绍: 重点概括:servlet运行在服务器上,处理用户请求. 我们使用response来获取一个写方法 PrintWriter o ...
- int *ptr=(int *)(&a+1)问题的探讨
从网络上看到这样一道有意思的题目,是关于数组与指针的问题,描述如下: main() { ]={,,,,}; ); printf(),*(ptr-)); } 输出为:2,5 请解释以上代码的输出结果. ...
- Ubuntu 16.04桌面打开终端自动进去桌面文件夹
sudo vim ~/.bashrc #在最后添加如下内容,注意,由于我的系统是中文版本,所以文件夹名称为“桌面”,如果为英文版的,那么需要更改为“Desktop” if [[ $PWD == $(r ...
- android Qemu GPS 模块简明分析
Android 的 gps module 是 gps.default.so 在system/lib/hw/ 文件夹上, 一般提供gps功能的手机应该实现这个module和真实gps硬件交互 Qemu ...
- UML中的四种关系总结
UML中的关系主要包含四种:关联关系.依赖关系.泛化关系.实现关系.当中关联关系还包含聚合关系和组合关系. 1. 关联关系(Association) 关联关系式一种结构化的关系,是指一种对象和还有一种 ...
- C语言++a与a++的实现机制与操作符结合优先级
看到一道"经典Linux C"面试题,关于左值和右值的. 华为笔试题 1.写出推断ABCD四个表达式的是否正确, 若正确, 写出经过表达式中 a的值(3分) int a = 4; ...