title Link: Http://codeforces.com/problemset/problem/567/B
Test instructions: The main idea: a counter, + number for a person to enter the library,-the number represents a person out of the library. Give a log, ask this log to know the smallest possible capacity of the library, log is a fragment, before the program run may have someone, after running also
Maybe people haven't gone out yet?
Method one: simulation;
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<vector>#include<map>#include<string>using namespacestd;#defineN 1000005#defineINF 0x3f3f3f3f#defineMet (A, b) memset (A, B, sizeof (a))typedefLong LongLL;intN, A[n], b[n];Chars[n][Ten];intMain () { while(SCANF ("%d", &n)! =EOF) {Met (A,0); Met (b,0); intAns =0; for(intI=0; i<n; i++) {scanf ("%s%d", S[i], &A[i]); if(s[i][0] =='+') B[a[i]]=1; Else if(B[a[i]] = =0) ans++;///first find out how many people in the original; } intMax =ans; for(intI=0; i<n; i++) { if(s[i][0] =='+') ans++; Elseans--; Max= Max (max, ans);///the quantity of circulating person in the process of re-statistic;} printf ("%d\n", Max); } return 0;}
View Code
Method Two: STL
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<vector>#include<map>#include<string>#include<Set>using namespacestd;#defineN 1000005#defineINF 0x3f3f3f3f#defineMet (A, b) memset (A, B, sizeof (a))typedefLong LongLL;intMain () {intN; while(~SCANF ("%d", &N)) {Set<int>s; intAns =0; for(intI=1; i<=n; i++) { Charch[5];intnum; scanf ("%s%d", CH, &num); if(ch[0] =='-'&& s.find (num) = =s.end ()) ans++; Else if(ch[0] =='-'&& s.find (num)! =s.end ()) s.erase (num); Else{s.insert (num); intLen =s.size (); Ans=Max (ans, Len); }} printf ("%d\n", ans); } return 0;}
View Code
B. Berland National Library---cf567b (set| Simulation)