Calculate the number of points in a line time limit:1 Sec Memory limit:64 MB
submit:820 solved:518
There are n lines on the description plane, and there are no three-wire common points, asking how many different cross-points these straight lines can have. For example, if n=2, the number of possible intersections is 0 (parallel) or 1 (not parallel). Input data contains multiple test instances, one row per test instance, each containing a positive integer n (n <=), and N represents the number of lines. Output each test instance corresponds to a row of outputs, listing all intersecting scenarios from small to large, where each number is the number of possible intersections, separated by a space between the integers in each row. Sample Input
23
Sample Output
0 10 2 3
A collection of intersection schemes that divides the M-line into two parts of R and M-r (n-N-lines of {nth})
Pay points=r* (m-r) +{m-r},dp[i][j] for the presence of flags,
1# include<stdio.h>2 intMain ()3 {4 //freopen ("A.txt", "R", stdin);5 intI,j,k,m,n;6 inta[ A][ $];7 8 while(SCANF ("%d", &n)! =EOF)9 {Ten for(i=0;i< the; i++) Onea[0][i]=0; A for(i=1; i<=n;i++) - { -a[i][0]=1; the for(j=1; j<= (I-1) *i/2; j + +) -a[i][j]=0; - for(j=1; j<i;j++) - { +m=i-J; - for(k=0; k<=m* (M-1)/2; k++) + { A if(a[m][k]==1) ata[i][k+j*m]=1; - /*printf ("%d,%d%d,%d\n", m,k,i,k+j*m); - printf ("\ n");*/ - } - } - } inprintf"0"); - for(i=1; i<=n* (n1)/2; i++) to { + if(a[n][i]==1) -printf"%d", i); the } *printf"\ n"); $ }Panax Notoginseng return 0; -}View Code
Calculate the intersection of a line