100 Floors of 2 eggs

Source: Internet
Author: User

There is a 100-storey building, an egg from the nth floor and above the floor will break, on the nth floor below the floor will not break. Give you 2 eggs, design a solution to find N, and ensure that in the worst case, minimize the number of egg drops.

Set the worst case of the number of K, if the first egg in the X-layer is broken, then the second egg should start from the 1th level to try to x-1 layer, the worst also try x-1 times, the total number of tests for 1+ (x-1) = k,x=k;

If the first egg is not bad for the first time in the X layer, the second break, at this time has been tested 2 times, then the second egg is the worst able to test k-2 times, set the second broken layer is Y, then the second egg should start from the X+1 layer test to y-1 layer, for k-2 times, namely (Y-1)-(x+1) +1=k-2 Because X=k, so y=2*x-1 =x+ (x-1) layer;

If the first egg is broken in the third time, ditto for the third time should be in x+ (x-1) + (x-2) layer

Up to x+ (x-1) + (x-2) +...+1 layer, should be greater than or equal to the total floor 100, i.e.

x + (X-1) + (x-2) + ... + 1 >= 100

(x+1) *X/2 >= 100

x=14;

So test up to 14 times, first on 14 levels, second at 27, and so on 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100;

100 Floors of 2 eggs

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.