Throwing chess pieces, throwing eggs, and throwing go games

Source: Internet
Author: User
Question 1:

Question: A rock will be broken when it is dropped at a certain height. It will not be broken below this height, and it must be broken above the height. Now there are 4 stones and a 1000-storey building. The height of the broken stone needs to be determined. The minimum number of times can be tested.

Question 2:

Question: A 100-storey building with two identical eggs (glass balls or go) in your hands ). Dropping eggs (glass balls or go) from a certain layer of the building will break down and use the two eggs in your hand (glass balls or go) to find an optimal strategy, to know the critical layer.

Question 3:

Question: There is a 100-storey building with two identical glass pawns in your hands. Dropping the pawns from a certain layer of the building will break down. Use the two glass pawns in your hands to find an optimal strategy to find out the critical layer.

This problem is generally expected to use a binary solution, but the maximum depth of the binary method is logn, so it is very important to choose a suitable stone-throwing layer.

Currently, the mainstream solution on the internet is dynamic planning, so I have a good learning experience. I think that the optimal solution for dynamic planning to solve this problem is to ensure that the number of throws is the least.

There are n floors and K balls

F (n, k) = min {max {f (R, k-1), F (R + 1, k)} + 1, 1 = <r <= n}

This indicates the meaning of F (n, k). The minimum number of K balls on N floors determines the critical layer.

In fact, R is used to indicate the layer from which I start the probe. Of course, you need to consider a certain layer from the first layer to the N layer to start processing.

This is assumed to be thrown from the R layer.

If the ball is broken, there must be a layer of critical left K-1 balls in the 1-r layer.

If the ball is not broken, K balls are left at the critical level in the r + 1-N layer.

Of course, F (n, k) is calculated based on the worst case, if you throw more times on the 1-r-1 layer than on the R-N layer, I need to record the number of times, of course, F (R, k-1) and vice versa.

Okay. code based on this idea

Question 1:

# Include "stdio. H "# define Max 1024 # define min 0x7fffffff # define num 10int f [Max] [num]; void find (int n, int K) {int R; int I; int J; int temp; int left; int right; int min; for (I = 2; I <= K; I ++) {for (j = 2; j <= N; j ++) {min = min; For (r = 1; r <= J; r ++) {left = f [r] [I-1]; right = f [J-R] [I]; temp = (left> right? Left: Right) + 1; if (temp <min) {min = temp ;}} f [J] [I] = min ;}} int main () {int N; int K; int I = 0; scanf ("% d", & K); scanf ("% d", & N); for (I = 1; I <= N; I ++) f [I] [1] = I-1;/* 1 ball detection I layer minimum I-1 times */for (I = 1; I <= K; I ++) f [1] [I] = 0;/* only one floor does not need to be checked */find (n, k ); printf ("% d \ n", F [N] [k]); Return 0 ;}

Answer 1: 13

Question 2 answer 14

Question 3 answer 14

Related Article

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.