Interview question-PHP logic algorithm: How many pieces of paper can be divided at most?

Source: Internet
Author: User
Question: {code...} answer: {code...} evaluate the algorithm {code...} question:

Draw 2999 straight lines on a blank sheet of paper. How many pieces of white paper can be divided at most? Write the computing Function

Answer:

//? Function maxBlock ($ num) {// @ todo how to calculate? }

Algorithm

MaxBlock (2999 );

Reply content:

Question:

Draw 2999 straight lines on a blank sheet of paper. How many pieces of white paper can be divided at most? Write the computing Function

Answer:

//? Function maxBlock ($ num) {// @ todo how to calculate? }

Algorithm

MaxBlock (2999 );

A line, as long as it is not parallel to any previous line, it is connected to all lines.
This can be done because the line slope can take any real number and infinity, Which is dense.
A line separates another line, which is equivalent to dividing the area below it.
In this case, we can obtain the recursive formula as follows:S (0) = 1; S (n) = S (n-1) + n;
S is almost the part of an Equality Series. After expansion, it is:S (n) = (1 + n) n/2 + 1;

Okay.S (n)Is what you wantMaxBlock (n).

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.