Question: There is a 100-story high-rise building. The glass ball dropped from a certain layer has just crashed. Now there are two glass balls. Try the easiest way to determine the layer where the glass ball is broken.
This is a famous interview question. I will only write my ideas and solutions.
First, get the basic idea from the question
1. The first ball should be low to a high level, but it is not required for each layer.
2. You cannot be lucky. The second ball is required for each layer of the first ball.
Is simplified to a 10-storey solution.
The number indicates the floor, and the number in the square corresponding to the path on the right and back of the ball from the origin is tested. that is, the first ball test Layer 4 \ 7 \ 9 \ 10. if Layer 4 of the first ball breaks down, the second ball tests 1 \ 2 \ 3. if the first ball breaks down on Layer 7, the second ball tests 5 \ 6. and so on, we can certainly measure the final number of layers. it is the best solution to achieve the result after four falls.
If each layer is regarded as a square with 1*1. it is similar to an isosceles trapezoid with an area of 4*4/2 + 4*0.5 = 10, that is, the number of layers. extended. The length of the edge is N. the number of layers it can test is N * n/2 + N * 0.5.
For the m floor, the optimal solution is the same as that for the M Floor. Deploy 1 to m according to the same method, and follow the path on the top right first. This is definitely the optimal solution.
That is, N * n/2 + N * 0.5> = m. Here, as long as the minimum positive integer of N is obtained, it is the maximum number of attempts.
For example, Layer 3. N * n/2 + N * 0.5> = 100. The minimum positive integer of the obtained N is 14.
The following demonstrates the correctness of the solution:
Converting actual problems into mathematical models is an important way to solve problems. If it is 16 floors, many people may soon come to the conclusion.
It is the first 4-Layer 4-layer test, and then each layer is required, the order in the figure is first right and then top. This is not the optimal solution, because if it is a bad layer of 15, try it seven times.
For example, the optimal solution for a 16-storey building based on my solution can be 6 times at most.
What is the optimal solution? The problem can already be converted to starting from the origin of the coordinate system. It can only start at the upper right corner, under the same area, which image minimizes the maximum distance from the origin point to any point in the image.
The conclusion is: in the same area, the maximum distance from the triangle with the Right waist to any point on the surface is the smallest. The distance from any point on the oblique side of a right-angle isosceles triangle to the origin is the same, which is also the biggest distance from the origin in the right-angle isosceles triangle. Using the reverse identification method, if there is a better image than a right-angle isosceles triangle, it is necessary to dig all the points on the oblique side, but where are these points? The location is far away from the current location.
In addition, if there are three, four, five, and N balls, they should be launched in a similar way. I have never calculated any of these values. I am very grateful to anyone who has obtained the calculation formula.
[This question algorithm is original to me. You are welcome to reference or repost it. please be sure to indicate the author and its source. Thank you !.
Http://blog.csdn.net/eversoutheast/article/details/2914396]
Question: There is a 100-story high-rise building. The glass ball dropped from a certain layer has just crashed. Now there are two glass balls. Try the easiest way to determine the layer where the glass ball is broken.
This is a famous interview question. I will only write my ideas and solutions.
First, get the basic idea from the question
1. The first ball should be low to a high level, but it is not required for each layer.
2. You cannot be lucky. The second ball is required for each layer of the first ball.
Is simplified to a 10-storey solution.
The number indicates the floor, and the number in the square corresponding to the path on the right and back of the ball from the origin is tested. that is, the first ball test Layer 4 \ 7 \ 9 \ 10. if Layer 4 of the first ball breaks down, the second ball tests 1 \ 2 \ 3. if the first ball breaks down on Layer 7, the second ball tests 5 \ 6. and so on, we can certainly measure the final number of layers. it is the best solution to achieve the result after four falls.
If each layer is regarded as a square with 1*1. it is similar to an isosceles trapezoid with an area of 4*4/2 + 4*0.5 = 10, that is, the number of layers. extended. The length of the edge is N. the number of layers it can test is N * n/2 + N * 0.5.
For the m floor, the optimal solution is the same as that for the M Floor. Deploy 1 to m according to the same method, and follow the path on the top right first. This is definitely the optimal solution.
That is, N * n/2 + N * 0.5> = m. Here, as long as the minimum positive integer of N is obtained, it is the maximum number of attempts.
For example, Layer 3. N * n/2 + N * 0.5> = 100. The minimum positive integer of the obtained N is 14.
The following demonstrates the correctness of the solution:
Converting actual problems into mathematical models is an important way to solve problems. If it is 16 floors, many people may soon come to the conclusion.
It is the first 4-Layer 4-layer test, and then each layer is required, the order in the figure is first right and then top. This is not the optimal solution, because if it is a bad layer of 15, try it seven times.
For example, the optimal solution for a 16-storey building based on my solution can be 6 times at most.
What is the optimal solution? The problem can already be converted to starting from the origin of the coordinate system. It can only start at the upper right corner, under the same area, which image minimizes the maximum distance from the origin point to any point in the image.
The conclusion is: in the same area, the maximum distance from the triangle with the Right waist to any point on the surface is the smallest. The distance from any point on the oblique side of a right-angle isosceles triangle to the origin is the same, which is also the biggest distance from the origin in the right-angle isosceles triangle. Using the reverse identification method, if there is a better image than a right-angle isosceles triangle, it is necessary to dig all the points on the oblique side, but where are these points? The location is far away from the current location.
In addition, if there are three, four, five, and N balls, they should be launched in a similar way. I have never calculated any of these values. I am very grateful to anyone who has obtained the calculation formula.
[This question algorithm is original to me. You are welcome to reference or repost it. please be sure to indicate the author and its source. Thank you !.