Algorithm: How many slashes can I cut a watermelon?

Source: Internet
Author: User
I just had an interview with algorithm questions and a watermelon. I kept the shape unchanged and cut up to 10 pieces! I just had an interview with algorithm questions,
The shape of a watermelon remains unchanged. You can cut up to 10 pieces with a knife! Reply content: you can find an answer:
How many pieces can a single watermelon cut with 100 knives be divided? Explain why.

The essence of your problem is the maximum number of spaces that can be divided into n planes. Let's look at the following three questions:
1) the maximum number of segments A straight line can be divided by n points. The general formula is recorded as A (n)
2) up to n straight lines can divide the plane into multiple areas. The general formula is recorded as B (n)
3) the maximum number of blocks in a space can be divided into n planes. The general formula is recorded as C (n)
The first question is very simple. A (n) = n + 1
The second problem is that if there are n straight lines on the plane and they divide the plane into the most area, when the n + 1 line goes down, in order to ensure that the most area is obtained, it is required that this line and the previous n lines both intersect, and the new point of intersection does not overlap with the previous point of intersection. obviously, the n + 1 line and the n line above generate n intersections, which divide the n + 1 line into A (n) segment, each segment splits the original region into two parts. Therefore, B (n + 1) = B (n) + A (n), and B (1) = 2, A (n) it is easy to obtain B (n) = [n (n + 1)/2] + 1 when bringing n + 1
The third question is how many blocks are added to the n + 1 plane. the n planes in front of the plane intersect with the n + 1 plane, leaving n intersections on the n + 1 plane, the n intersections divide the n + 1 plane into B (n) areas at most, and each area splits the original blocks into two, so C (n + 1) = C (n) + B (n), convert C (1) = 2, B (n) = [n (n + 1) /2] + 1 can be obtained C (n) = [(n ^ 3 + 5n)/6] + 1
Tip: Use the following summation formula:
1 + 2 +... + n = n (n + 1)/2
1 ^ 2 + 2 ^ 2 +... + n ^ 2 = n (n + 1) (2n + 1)/6
Bringing n = 100 into C (n) to C (100) = 166751 if the knife is straight and it is a 10-dimensional watermelon, the answer is 1024. Is it 3D? It is not easy to calculate .. For those who say 1024, they are all moving watermelons in the middle, or even 10-dimensional space.
Without moving the watermelon, the fourth knife could not cut out 16 pieces. Do not understand algorithms,
But I feel that if the nth knife and the first n-1 knife are all intersecting, this should be the case with the most blocks,
1 + (1/2) (n + 1 ))
56
Well, this seems to be a two-dimensional watermelon. The number of pieces that can be cut out with 10 knives in each dimension is as follows:
1 dimension: 11
2-dimension: 56
3D: 176
4-dimension: 386
5 dimensions: 638
Dimension 6: 848
7-dimension: 968
8-dimension: 1013
9-dimension: 1023
10 + dimensions: 1024
Generally:
The maximum number of chunks that can be cut out by a knife in a dimension space is the anterior coefficient and (0 for no items) of the sub-binary expansion ).
For example, a maximum of 1 + 3 + 3 = 7 pieces can be cut out with three knives in two-dimensional space. My first reaction was to use the greedy algorithm. Ten power of two
1024 it's perfect with a single shot,
Let's make a joke. The next step is a positive solution.
The answer to the subject's question is unclear. There is no limit on whether to move the watermelon during the cutting process.
1. Yes.
The answer has already been answered by the various immortals. 10 ^ 10 = 1024

2. No.
At this time, we need to make contributions to the primary school Olympics (the elementary school has entered the pit and passed the test in Hangzhou 34, but it is too bad for all great gods)
0 knives: 1
1 knife: 2 (nonsense)
2 knives: 4
3: 8 pieces (cut into the shape of second-order cube)
It is not surprising to see this, because it seems that something happens 2 ^ n ?, This is because within three knives, we can ensure that the small pieces cut out from each previous plane are cut into two pieces.
4 knives: 15 pieces (you can try it yourself, but you can find that you cannot cut 16 pieces)
This is because we cannot split each small block into two parts. Then the data is listed.
1, 2, 4, 8, 15
Keke, let's make a difference.
1, 2, 4, 7
What's the rule? Continue to make the difference
1, 2, 3. That's right. This series is perfect. The difference is 1.

This can be recursive.
93,130,176

1, 2, 3, 4, 5, 6, 7, 8, 9, 10
1, 1, 1, 1, 1, 1, 1, 1
(The following column serves as the tolerances of the above column, and goes up in turn) [by Zhiyou, add 1111111 in the last column]
Therefore, the answer should be 176. According to the ticket to answer this question @ Huang Ge, I wrote the Python algorithm implementation.
The Code is as follows:

def A(n):    return n+1def B(n):    if n==1:        return 2    return B(n-1)+A(n-1)def C(n):    if n==1:        return 2    return B(n-1)+C(n-1)print str(C(10))

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.