201,600-degree Internship side

Source: Internet
Author: User

There are a total of four questions, the other three feeling is relatively simple, the first question records the number of words, but the number of words is more, so use map to engage. The second question traverses the tree, drawing the depth of each node in the tree. The third problem is to find a single LCA.

The most difficult problem is a thinking problem, give the number of N (n<=10^6), if there are two number A, B, to meet 2*a<=b, you can put the number a in the number B, each number can be a maximum of one number, ask the maximum number of numbers to be installed?

For a litchi:

Suppose now n=5

These 5 numbers are: 4 1 2 8 9

Let's first Order 1 2 4 8 9

Then the 1->2,4->8 is loaded with a maximum of two.

At this point it is easy to think of several greedy strategies, such as sorting, from the smallest start greedy, or from the biggest start greedy.

Here is a set of data to show that this greed is wrong.

N=4

1 2 4 7

N=4

3 5 10 20

And see how this problem should be thought.

First of all, to find a key property, after sorting, there must be a number of x, so that the optimal solution is loaded in the number on the left side of X, loading the number on the right side of X.

Next look at the picture.

201,600-degree Internship side

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.