Calculate the intersection of a line

Source: Internet
Author: User

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

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.