The second question:
[Programming questions] stick puzzle
There is a set composed of a lot of sticks, each stick has a corresponding length, I wonder if the collection of these sticks in a certain order to form a simple polygon area greater than 0 and all the sticks are to be used, simple polygons will not be self-intersection polygon.
The initial collection is empty, there are two operations, either add a stick with a length of L to the collection, or delete a stick already in the collection. At the end of each operation you need to tell if you can use these sticks in the collection to form a simple polygon.
Input Description:
Each set of test cases contains only one set of data, the first behavior of each group of data is a positive integer n represents the number of operations (1≤n≤50000), followed by n rows, the first integer per line is the operation type I (i∈{1,2}), the second integer is a length of L (1≤l≤1,000,000,00 0). If the i=1 represents inserting a stick with a length of L in the set, if i=2 represents the deletion of a stick of length l within the set. The input data guarantees that the collection must have a stick of length L at the time of deletion, and that the collection is non-empty after any operation.
Output Description:
For each operation end there is one output, if the stick within the set can form a simple polygon, output "Yes", otherwise output "No".
Input Example:
51 11 11 12 11 2
Output Example:
Nonoyesnono
Attention:
multiset<ll>s;
To delete a number using multiset:
S.erase (S.find (y));
Use
S.erase (y);
will delete the same number together
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <Set>6 7 using namespacestd;8 9 #defineN 50005Ten #definell Long Long One A ll sum; - ll Ma; - intN; the intsz; - - intMain () { - while(SCANF ("%d", &n)! =EOF) { +Ma =0; -sum =0; +Multiset<ll>s; AMultiset<ll>:: iterator it; at inti; - intx; - ll y; - for(i =0; I < n;i++){ -scanf"%d%lld",&x,&y); - if(x = =1){ in S.insert (y); -Sum + =y; to } + Else{ - s.erase (S.find (y)); theSum-=y; * } $it =s.end ();Panax NotoginsengIt--; -Ma = *it; theSZ =s.size (); + if(SZ >=3&& (SUM-MA) >Ma) { Aprintf"yes\n"); the } + Else{ -printf"no\n"); $ } $ } - } - the}
Today's headline 2017 back-end engineer Intern Pen Questions