Today's headline 2017 back-end engineer Intern Pen Questions

Source: Internet
Author: User

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

Contact Us

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.