Problem description
There are n straight lines on the plane, and there are no three-line common points. Ask how many different kinds of intersection points are there for these straight lines.
For example, if n = 2, the number of possible intersections is 0 (parallel) or 1 (non-parallel ).
Input
The input data contains multiple test instances. Each test instance occupies one row and each row contains a positive integer n (n <= 20). N indicates the number of straight lines.
Output
Each test instance corresponds to a line of output, listing all the intersection schemes from small to large, each of which is a possible number of intersection points, each line of integers are separated by a space.
Sample Input
2
4
Sample output
0 1
0 3 4 5 6 (indicating that in the case of 4 straight lines, there may be 0, 3, 4, 5, 6 intersections)
Problem AnalysisLine 2 and line 1 have at most one intersection, and line 3 and line 1 have at most two intersections ,......, line N and other n-1 lines have a maximum of n-1 intersections. The maximum number of intersection points for n straight lines that are not parallel to each other and have no three-line common points are obtained: max = 1 + 2 + .... (N-1) = N (n-1)/2; but this question is not so simple. How many different points are there for these straight lines?
It is easy to list the situations I = 1, 2, 3, as shown in to analyze the situations where N = 4: 1. all four straight lines are parallel, with no intersection. among the three parallel nodes, the intersection points: (n-1) * 1 + 0 = 3; 3. two of them are parallel, and the intersection of the other two straight lines can be parallel or intersection, so the intersection data is: (n-2) * 2 + 0 = 4 (n-2) * 2 + 1 = 54. the four straight lines are not parallel, the intersection points are (n-3) * 3 + 3 of the intersection of the line :( n-3) * 3 + 0 = 3
(N-3) * 3 + 2 = 5
(N-3) * 3 + 3 = 6 that N = 4, 0, 3, 4, 5, 6 different points. from the above n = 4 analysis process, we found that the number of intersection points of m straight lines = (m-R) intersection points between parallel lines and R straight lines + intersection points between R straight lines = (m-R) * R + intersection points between R straight lines.
# Include <stdio. h>
Int main ()
{
Int I, j, N, F [21] [1, 191];
// F [I] [J] indicates whether J nodes can be generated when an I edge is added. If yes, 1 is returned. If no, 0 is returned.
For (I = 0; I <21; I ++)
For (j = 0; j <191; j ++)
F [I] [J] = (j = 0 );
// F [I] [0] is set to 1
For (n = 2; n <21; n ++)
For (I = n-1; I> = 1; I --)
For (j = 0; j <191; j ++)
If (F [n-I] [J] = 1)
F [N] [J + (n-I) * I] = 1;
// If f [N] [x] = 1
// F [N] [x + (n-I) * I)] = 1
While (scanf ("% d", & N )! = EOF)
{
Printf ("0 ");
For (j = 1; j <= N * (n-1)/2; j ++)
If (F [N] [J])
Printf ("% d", J );
Printf ("/N ");
}
Return 0;
}