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)