Copy codeThe Code is as follows:
<Html>
Question: <br/>
A maximum of n straight lines can divide a plane into several parts <br/>
Number of lines: <input type = "text" id = "line"/> <br/>
Inner point: <label id = "innerPoint"> </label> <br/>
Number of partitions: <label id = "part" style = "background: yellow;"> </label> <br/>
<Input type = "button" onclick = "calculate ()" value = "computing"/>
</Html>
<Script type = "text/javascript">
Function calculate (line)
{
Var line = document. getElementById ('line'). value;
If (line = "")
{
Line = 0;
Document. getElementById ('line'). value = line;
}
Var line = parseInt (line );
Var innerPoint = line * (line-1)/2;
Var part = (Math. pow (line, 2) + line)/2 + 1; // line + innerPoint + 1 equals (the square of the number of lines + the number of lines)/2 + 1
Document. getElementById ('innerpoint'). innerText = innerPoint;
Document. getElementById ('part'). innerText = part;
}
</Script>
Rule:
① Most divided parts: number of lines + inner points + 1
② Inner point = (number of lines-1) Inner point + (number of lines-1), the newly added line can have an intersection with other lines
③ Use recursion to find the number of inner points, and then substitute it into ① for Calculation
The above is a normal mathematical thinking. Next we will talk about the field testing knowledge that I use, that is, the stuff of my code.
I listed 1 ~ Some available parameters for five straight lines:
Number of intersection diplomatic points in a straight line
1 0 2 2
2 1 4 4
3 3 6 7
4 6 8 11
5 10 10 16
It is found that diplomatic points are meaningless, and they are two times the number of straight lines.
The part number = the number of straight lines + the number of inner points + 1
The number of intersections in the number of adjacent straight lines forms an arithmetic difference series. The tolerances of this arithmetic difference series are 1, 1-0 =-1 =-3 =-6 = 4, 1 + 0 = 1 + 1 = 3 + 3 = 6... however, we still use recursion to obtain the number of corresponding inner intersections, so we look at the Law vertically, 2*1 = 2 3*2 = 6 4*3 = 12... exactly twice the number of inner points