Hdu1466 calculate the intersection points of a straight line (finding rules + mathematics)

Source: Internet
Author: User

Reprint please indicate the source: http://blog.csdn.net/u012860063? Viewmode = Contents

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1466


Calculate the intersection points of a straight line. The problem description plane has n straight lines without the Three-line common points. Ask how many different kinds of intersection points can be obtained for these straight lines.
For example, if n = 2, the number of possible intersections is 0 (parallel) or 1 (non-parallel ). The input data contains multiple test instances. Each test instance occupies one row. Each row contains a positive integer n (n <= 20). N indicates the number of straight lines.
Output: each test instance corresponds to a single line of output, and all the intersection schemes are listed from small to large. Each number of possible intersection points is separated by a space.
Sample Input
23

Sample output
0 10 2 3

The Code is as follows:

# Include <cstring> # include <iostream> using namespace STD; # define N 21 # define M (N-1) * n/2int DP [N] [m]; // DP [I] [J] I is a line where J represents the number of intersections void solve () {int m = 0; memset (DP, 0, sizeof (DP); DP [0] [0] = 1, DP [1] [0] = 1; for (INT I = 2; I <= 20; I ++) {for (int K = 0; k <I; k ++) {for (Int J = 0; j <= K * (k-1)/2; j ++) {If (DP [k] [J]) {M = J + K * (I-k); DP [I] [m] = 1; // tag }}} int main () {int N; solve (); While (~ Scanf ("% d", & N) {printf ("0"); For (INT I = 1; I <= N * (n-1)/2; I ++) {If (DP [N] [I]) {printf ("% d", I) ;}} printf ("\ n ");} return 0 ;}


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.