Poj 3304 segments [calculation ry] [relationship between a straight line and a line segment]

Source: Internet
Author: User

Question link: http://poj.org/problem? Id = 3304

T case, each case contains n lines to determine whether a straight line exists, so that all lines can have common points in this line. If yes is output, otherwise, no is output.

The meaning of the question can be changed to: Can two vertices in 2 * n endpoints of n straight lines form a straight line to meet this condition, brute force enumeration is enough, note that the two points selected each time in the 2 * n vertices of the enumeration should be used to determine whether they are repeated.

# Include <iostream> # include <stdio. h> # include <math. h> # include <cstring> # include <stdlib. h> using namespace STD; # define EPS 1e-8 # define zero (x)> 0? (X):-(x) <EPS) // if it is 0, 1 is returned. Otherwise, 0 # DEFINE _ sign (x)> EPS? 1 :( (x) <-EPS? 2: 0) // negative 0 returns 2 0 1 struct point {Double X; Double Y; point (const double & x = 0, const double & Y = 0 ): x (x), y (y) {}void in () {scanf ("% lf", & X, & Y) ;} void out () const {printf ("%. 2f %. 2f \ n ", x, y) ;}; struct line {point a, B; line (const point & A = point (), const point & B = point (): A (a), B (B) {} void in () {. in (); B. in ();} void out () const {. out (); B. out () ;};// calculate the cross (P1-P0) x (P2-P0) Double xmult (Point P1, point P2, point P0) {// P0 is the center return (p1.x-1_x) * (p2.y-1_y)-(p2.x-1_x) * (p1.y-policy);} // returns 1int same_side (point P1, point P2, line L) {return xmult (L. a, P1, L. b) * xmult (L. a, P2, L. b)> EPS;} line L [105]; point P [500]; int N; int judge (line LL) {If (_ sign (LL. a. x-LL. B .x) = 0 & _ sign (LL. a. y-LL. B .y) = 0) return 0; For (INT I = 0; I <n; I ++) {If (same_side (L [I]. a, L [I]. b, LL) = 1) return 0;} return 1;} int Main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); for (INT I = 0; I <n * 2; I ++) P [I]. in (); For (INT I = 0; I <n; I ++) {L [I]. A = P [I * 2]; L [I]. B = P [I * 2 + 1];} int flag = 0; For (INT I = 0; I <n * 2-1; I ++) for (Int J = I + 1; j <n * 2; j ++) {line LL; ll. A = P [I]; ll. B = P [J]; If (Judge (LL) = 1) {flag = 1; break ;}} if (flag = 1) cout <"Yes! "<Endl; else cout <" No! "<Endl ;}}


Poj 3304 segments [calculation ry] [relationship between a straight line and a line segment]

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.