1. 程式人生 > >ACM-FJNU18級第二次友誼賽F題-認真讀題

ACM-FJNU18級第二次友誼賽F題-認真讀題

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; //學藝不精,告辭
}

打程式碼就像翻譯題。