CodeForces - 567B Berland National Library
来源:互联网 发布:我心伤悲 莫知我哀赏析 编辑:程序博客网 时间:2024/05/18 01:46
题目大意:有一个房间,+ 表示进,- 表示出,后面的数字代表编号,问该房间最少能同时容纳多少人。
解题思路:用 now 统计当前人数,tot 表示历史最多人数,每改变一人就比较一次,注意 - 时会有两种情况,一开始不知道如何处理本来就在房间内的人,卡了很久,心塞
#include<iostream> #include<cstdio>#include<string.h>#include<stdlib.h>#include<cmath>using namespace std;int r[1000010];int main() { int n; while(scanf("%d", &n) != EOF) { memset(r, 0, sizeof(r)); char c; int tag; int tot = 0,now = 0; for (int i = 0; i < n; i++) { getchar(); c = getchar(); scanf("%d", &tag); if (c == '+') { r[tag] = 1; now++; } if (c == '-') { if (r[tag] == 1) { r[tag] = 0; now--; } else if (r[tag] == 0) tot++; } tot = max (tot, now); } printf("%d\n", tot); } return 0; }
1 0
- Codeforces 567B Berland National Library
- Codeforces 567 B. Berland National Library
- CodeForces 567B Berland National Library
- CodeForces 567B Berland National Library
- CodeForces 567B Berland National Library
- CodeForces - 567B Berland National Library
- CodeForces-567B Berland National Library
- CodeForces 567B-Berland National Library
- CodeForces 567B Berland National Library
- Berland National Library CodeForces - 567B
- CodeForces 567B Berland National Library【思维】
- Codeforces B - Berland National Library
- CodeForces 567- Berland National Library
- CodeForces 567B Berland National Library 容器模拟
- codeforces(567A)--A. Lineland Mail--B. Berland National Library
- CodeForces 567B Berland National Library(模拟)(简单)
- B. Berland National Library
- Code Forces 567B Berland National Library
- 文章标题
- iOS开发中的事件处理(二)-事件传递,响应者链条
- 编程之美 - 电话号码对应英语单词
- CSS 最小高度
- Constraint 约束增强说明
- CodeForces - 567B Berland National Library
- Android调试命令小结
- 【HDU 5720】Wool(排序+排序/扫描线。。。)
- 错误票据
- 杭电ACM 1048
- CC2540/CC2541/CC254x之可变参数串口打印配置
- jQuery学习<五> — — 选择器(下)
- HDU - 4730 We Love MOE Girls
- 关于eclipsetomcat部署项目路径修改