ACM-FJNU18级第二次友谊赛F题-CodeForces-567B 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 room visitors’ accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form “reader entered room”, “reader left room”. Every reader is assigned a registration number during the registration procedure at the library — it’s a unique integer from 1 to 106. Thus, the system logs events of two forms:
“+ ri” — the reader with registration number ri entered the room;
“- ri” — the reader with registration number ri left the room.
The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.
Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.
Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.
INPUT
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as “+ ri” or “- ri”, where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).
It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct.== Before starting the system, and after stopping the room may possibly contain visitors.==
OUPUT
Print a single integer — the minimum possible capacity of the reading room.
这题的话,还是要读题的,认真读题。
大概意思就是寻找容器内元素最多的情况然后输出就行。
只需要先int main()然后scanf然后这样这样再printf就行了嗯嗯嗯!
关键点在代码里面讲吧ouo
AC代码
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#define N 1000050
#define double pai = 4.0*atan(1.0)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long int ll;
ll ar[N];
ll br[N];
int main()
{
int n ;
scanf("%d",&n);
char ch;
int i;
int med_1=0,med_2=0;
mes(br ,0);
mes(ar, 0);
while(n--)
{
getchar();//想想为什么要用一个getchar()读一下
scanf("%c %d",&ch,&i);
if(br[i]==0&&ch=='-') med_1++; //0代表不是后来进入的,每个出去的人加到原数量去。
else if(ch=='-') {//此时表示这个人是启动之后进来再出去,实时数量减一
med_2--;
}
else if(ch=='+'){
med_2++;
br[i]=1;//记录
med_1= med_1>med_2?med_1:med_2;//只实时数量与原数量中最大的一个
}
}
printf("%d\n",med_1);
return 0; //学艺不精,告辞
}
打代码就像翻译题。