Codeforces Round #Pi (Div. 2) B Berland National Library

思路:对于这道题,一开始并没有什么思路,但后来想了下,其实就是维护一个集合,每一个人都是不同的元素,满足了集合的互异性,而要求这个图书馆最小的容纳量,其实就是求这个集合的最大的元素量,假设在某个时刻集合里存在M个元素,是集合从开始到结束出现过的元素个数的最大值,那么就是这个图书馆的最小容纳量,如果最小容纳量比M小,那怎么容得下M个人?对于+,   他之前肯定是没进或者之前出来股,无论怎样,都要加进集合。

对于一个集合的操作,在cf种时间为上的比赛,自然选用stl的set,如果各位有更好的思路或实现方法,一定要指教我

题目链接:http://codeforces.com/problemset/problem/567/B

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
using namespace std;
int main(void)
{
    int n;
    while(~scanf("%d",&n))
    {
        set<int> s;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            getchar();
            char ch;int num;
            scanf("%c",&ch);
            scanf("%d",&num);
            if(ch=='+')
            {
                s.insert(num);
                int d=s.size();
                ans=max(d,ans);
            }
            else
            {
              if(s.find(num)==s.end())
                 ans++;
               else s.erase(num);
               int d=s.size();
               ans=max(d,ans);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

版权声明:转载务必请标明出处,谢谢

时间: 2024-08-24 01:23:36

Codeforces Round #Pi (Div. 2) B Berland National Library的相关文章

构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

题目传送门 1 /* 2 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 3 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 0:23:37 8 * File Name :B.cpp 9

Codeforces Round #Pi (Div. 2)——set——Berland National Library

Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading roo

Codeforces Round #Pi (Div. 2) ——B. Berland National Library

这道题我一开始想了很久,但是fst 了.而且赛后想的也不是很清楚,所以有必要把它单独分出来讲清楚. 题意: 现在在log中有n条记录.然后每一条记录都写成:"+ri"或是"-ri"的形式.(其中+是代表有人进入,-代表有人出去)ri代表的是进入人的号码. 然后问你房间中最多同时有几个人存在. 思路: 我们需要两个变量max与sum,其中max是记录房间的最大容量的,sum是表示当前还有多少空位. 1)如果一个人进来了,如果当前没有空位的话,那么就max++,使房间容

Codeforces Round #Pi (Div. 2) (STL专场)

Codeforces Round #Pi (Div. 2) A - Lineland Mail 水题,拼手速. /* * @author Novicer * language : C++/C */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue

map Codeforces Round #Pi (Div. 2) C. Geometric Progression

题目传送门 1 /* 2 题意:问选出3个数成等比数列有多少种选法 3 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 1:07:18 8 * File Name :C.cpp 9 *************************

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #Pi (Div. 2)(A,B,C,D)

A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include

Codeforces Round #Pi (Div. 2) E. President and Roads (最短路+强连通求割边)

题目地址:codeforces #pi (DIV2) E 题目很水..就是先求两边最短路,然后把可能为最短路的边挑出来,然后判断是否yes只需要转化成无向图跑一遍tarjan,找出割边,割边就是yes,然后剩下的边就让它的值为最短路-1就行了,如果-1后变成了非正数,就是no. 但是!!!居然卡spfa!!那是不是说cf以后就不能用可以卡的算法了..完全可以出组数据来卡这些算法...比如spfa,isap... 于是为了这题,又看了一遍迪杰斯特拉算法.. 代码如下: #include <cstd

Codeforces Round #Pi (Div. 2) —— C-Geometric Progression

题意: 现在有n个数,然后给出一个数k(代表的是等比数列中的那个公比),然后第二行给出n个数,代表的是这个序列. 最后的问题是叫你找出在这个序列中满足公比为k的三个数有几种,并输出方案总数. 思路: 这道题很巧妙啊,用到了map. 首先我们先记录下每种数出现过了几次,这里因为数太大了,直接用数组存会爆掉,所以改用map. 我们需要两个map,分别记为mp1,mp2. 然后在for的过程中,我们是以当前的那个数为第二项,然后去寻找它的mp1[a[i]*k](也就是第三项),寻找它的mp2[a[i]