CodeForces 567B Berland National Library hdu

  这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可

 1 #include<cstdio>
 2 #include<cstring>
 3
 4 const int HASH=57;
 5
 6 int n,num[110],head[HASH],next[110];
 7
 8 void insert(int s)
 9 {
10     int h=num[s]%HASH;
11     int u=head[h];
12     while(u) u=next[u];
13     next[s]=head[h];//原来的链表头成为s的next
14     head[h]=s;//s成为head[h]的链表头
15 }
16
17 int erase(int s)
18 {
19     int h=num[s]%HASH;
20     int u=head[h];
21     while(u)
22     {
23         if(num[u]==num[s])
24         {
25             num[u]=0;
26             return 1;
27         }
28         u=next[u];
29     }
30     return 0;
31 }
32
33 int main()
34 {
35     while(scanf("%d",&n)==1)
36     {
37         int x,cap=0,j=1,maxcap=0;
38         char op[2];
39         memset(head,0,sizeof(head));
40         for(int i=1;i<=n;i++)
41         {
42             scanf("%s%d",op,&num[j]);
43             if(op[0]==‘+‘)
44             {
45                 insert(j);
46                 j++;
47                 cap++;
48                 //printf("cap=%d\n",cap);
49                 if(cap>maxcap) maxcap=cap;
50             }
51             else
52             {
53                 if(erase(j)) cap--;
54                 else maxcap++;//在记下maxcap之前已经在里面
55                 //printf("cap=%d\n",cap);
56                 if(cap>maxcap) maxcap=cap;
57             }
58         }
59         printf("%d\n",maxcap);
60     }
61     return 0;
62 }

 1 #include<cstdio>
 2 #include<cstring>
 3
 4 int T,n,a,b,L,cas=1;
 5
 6 int main()
 7 {
 8     scanf("%d",&T);
 9     while(T--)
10     {
11         scanf("%d%d%d%d",&n,&a,&b,&L);
12         int l,r,strength=0,min=0,last=0;
13         for(int i=0;i<n;i++)
14         {
15             scanf("%d%d",&l,&r);
16             strength+=b*(l-last)-a*(r-l);
17             if(strength<min) min=strength;
18             last=r;
19         }
20         printf("Case #%d: %d\n",cas++,-min);
21     }
22     return 0;
23 }

时间: 2024-08-07 08:58:51

CodeForces 567B Berland National Library hdu的相关文章

CodeForces 567B Berland National Library

Description 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

CodeForces 567B Berland National Library(模拟)(简单)

B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland National Library has recently been built in the capital of Berland. In addition, in the library you can t

构造 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-B. 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

D - 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

Berland National Library codeforces 567B(模拟)

http://codeforces.com/problemset/problem/567/B 题意:图书馆有一个程序,可以记录学生的进出情况,'+'表示进入,'-'表示出去,字符后面的数字表示学生的编号.在这个程序尚未启动前,还有一些同学进的消息没有被记录下来.现在问你这个图书馆至少得容纳多少学生. 分析:用sum和ans两个值来记录,sum存当前房间人数,ans维护最大值. #include <iostream> #include <stdio.h> #include <s

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

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

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

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