Poj 3304 determines the intersection of a line segment and a straight line

Source: Internet
Author: User

Question: n lines are given to determine whether there is a straight line. All lines must have at least one public point after the projection of a straight line (intersection with all lines)

I started to think wrong, because it is to determine whether a line exists in the given line segment to make it intersect with all line segments;

This can also pass the sample input;

I have been searching for it for a day;

# Include <iostream> # include <cmath> # include <cstdlib> # include <cstdio> using namespace STD; const double EPS = 1e-8; const int maxn = 100 + 5; struct point {Double X; Double Y; point (double A = 0, double B = 0) {x = A; y = B ;}} P [maxn * 2]; struct line {Point U; point V;} l; int t, n; int sig (Double X) {return (x> EPS)-(x <-EPS ); // return x <-EPS? -1: x> EPS; // This is also a line} double mult (point P1, point P2) // two-point cross product {return p1.x * p2.y-p1.y * p2.x ;} double mult (point P0, Point P1, point P2) // three-point cross product {return (p1.x-converted X) * (p2.y-converted y)-(p2.x-converted X) * (p1.y-policy);} int same_site (point P1, point P2, line L) // Point P1 & p2 on the same site of line l {int A = sig (mult (L. u, L. v, P1); int B = sig (mult (L. u, L. v, P2); return a * B> 0;} int judge (line L) {If (SIG (L. u. x- L. v. x) = 0 & sig (L. u. y-L. v. y) = 0) return false; For (INT I = 1; I <2 * n; I + = 2) if (same_site (P [I], P [I + 1], L) return false; return true;} int slove () {for (INT I = 1; I <n * 2; I ++) {for (Int J = I + 1; j <= N * 2; j ++) {L. u. X = P [I]. x; L. u. y = P [I]. y; L. v. X = P [J]. x; L. v. y = P [J]. y; If (Judge (L) // if it succeeds, return true;} return false;} int main () is found () {# ifndef online_judge freopen ("in", "r", stdin); # endi F CIN> T; while (t --) {CIN> N; For (INT I = 1; I <= N * 2; I ++) {CIN> P [I]. x> P [I]. y;} If (slove () puts ("Yes! "); Else puts (" No! ");}}

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.