# B. Berland National Library---cf567b (set| Simulation)

Source: Internet
Author: User

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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.