Poj 3304 segments-intersection of straight lines and Line Segments

Source: Internet
Author: User
/* Question: Ask some line segments if there is such a line: all these line segments have a common point projected on the line. If there is such a point, make the vertical line of this line, this vertical line is crossed by all line segments because the projection of all line segments covers this point, because their projection has this common point, it is to find a straight line that passes through all line segments. So, enumerate the straight lines composed of any two points to see if they meet the requirements */# include <stdio. h> # include <math. h> const double zero = 1e-8; struct point {Double X, Y ;}; struct segment // line segment {Point P1, P2;} s [110]; point PP [210]; // All Village Points int t, n; int equal (point P1, point P2) // determine whether it is the same point {If (FABS (p1.x-p2.x) <= zero & FABS (p1.y-p2.y) <= zero) return 1; return 0;} doubl E cross (point P, point V1, point V2) // performs the cross product {return (v2.x-v1.x) * (p. y-v1.y)-(P. x-v1.x) * (v2.y-v1.y);} int scrossl (point S1, point S2, point L1, point L2) // determine whether a straight line passes through a line segment {If (Cross (S1, l1, L2) * Cross (S2, L1, L2) <= 0) return 1; return 0;} int main () {int I, J, K; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 0; I <N; ++ I) {scanf ("% lf", & S [I]. p1.x, & S [I]. p1.y, & S [I]. p2.x, & S [I]. p2.y); PP [I * 2 + 0]. X = s [I]. p1.x; PP [I * 2 + 0]. y = s [I]. p1.y; PP [I * 2 + 1]. X = s [I]. p2.x; PP [I * 2 + 1]. y = s [I]. p2.y;} for (I = 0; I <2 * n-1; I ++) {for (j = I + 1; j <2 * n; ++ J) // enumeration point {If (! Equal (PP [I], PP [J]) // not the same point {for (k = 0; k <n; k ++) // test all side if (! Scrossl (s [K]. p1, s [K]. p2, PP [I], PP [J]) break; If (k = N) Break ;}} if (k = N) break ;} if (k = N) printf ("Yes! \ N "); else printf (" No! \ 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.