Home > Web Front-end > JS Tutorial > body text

Share a written test question [How many parts can a plane be divided into with n straight lines at most]_javascript skills

WBOY
Release: 2016-05-16 17:49:17
Original
1422 people have browsed it
Copy code The code is as follows:


Question:

The maximum number of parts that can be divided into a plane by n straight lines


Number of lines:

Inner intersection point:

Number of divisions:





Tell me the rules:

①The most divided parts: Number of lines Number of internal intersection points 1

②The number of internal intersection points = the number of internal intersection points (number of lines-1), the newly added line may have intersections with other lines

③ Use recursion to find the number of internal intersection points, and then substitute it into ① to calculate

The above is normal mathematical thinking. Next, I will talk about the practical test knowledge I use, which is the stuff of my code

I have listed some available parameters for 1~5 straight lines:

Line numbers, internal intersection points, diplomatic points, partial numbers

1  0  2  2

2 1 4 4

3 3 6 7

4 6 8 11

5 10 10 16

I found that diplomatic points are meaningless, anyway they are twice the number of straight lines

And the number of parts = the number of straight lines and the number of internal intersection points 1

The number of intersection points within the number of adjacent straight lines forms an arithmetic sequence. The tolerance of this arithmetic sequence is 1, 1-0=1, 3-1=2, 6-3=3, 10-6=4, Looking horizontally, 1 0=1,2 1=3,3 3=6...But this still uses recursion to find the number of corresponding internal intersection points, so looking at the pattern vertically, 2*1=2 3*2= 6 4*3=12...exactly twice the number of internal intersection points

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!