Calculate the number of intersections of a straight line (set + dial table)

Source: Internet
Author: User

Calculate the intersection of a line

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 9357 Accepted Submission (s): 4226

Problem description plane has n lines, and there is no three-wire common point, ask these straight line can have how many different intersection points. For example, if n=2, the number of possible intersections is 0 (parallel) or 1 (not parallel).

Input data consists of multiple test instances, one row per test instance, each containing a positive integer n (n<=20), and n representing 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 Input23

Sample Output0 10 2 3

The best way to use ST is to save the number of points in line I, then enumerate the number of lines J; The number of the current point is *iter+ parallel * not parallel, draw a picture to see just fine;

Think about it, write it down, a bit of DP means

Code:

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<Set>using namespacestd;Set<int>st[ -];Set<int>:: iterator iter;voiddb () {st[1].insert (0);  for(inti =2; I < -; i++) {St[i].insert (0);  for(intj =1; J < I; J + +){             for(iter = St[i-j].begin (); ITER! = St[i-j].end (); iter++){                intDot = *iter + (i-j) *J;             St[i].insert (dot); }        }    }    }intMain () {intN;    DB ();  while(~SCANF ("%d", &N)) {         for(iter = St[n].begin (); ITER! = St[n].end (); iter++){            if(iter! = St[n].begin ()) printf (" "); printf ("%d", *ITER); } puts (""); }    return 0;}

Calculate the number of intersections of a straight line (set + dial table)

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.