POJ 1269 (intersection of straight lines)

Source: Internet
Author: User

Language: Intersecting LinesTime Limit: 1000 MS Memory Limit: 10000 KTotal Submissions: 7657 Accepted: 3510Description calculates the intersection of two straight lines. The given coordinates range from-1000 to 1000 and are integers. the number of data groups in the first row of Input is less than or equal to 10 and then N rows. Each row is x1y1x2y2x3y3x4y4. indicates that the first line goes through (x1, y1), (x2, y2), the second line goes through (x3, y3), and (x4, y4 ). ensure that the line can be determined. output output n + 2 first line Output intersecting lines output. next, the output intersection of each row is none, line, or point x y (retain 2 decimal places ). the last line outputs "end of output ". sample Input50 0 4 4 0 4 05 0 7 6 1 0 2 35 0 7 6 3-6 4-32 0 2 27 1 5 18 50 3 4 0 1 2 5 Sample outputINTERSECTING lines outputpoint 2.00 2.00 NONELINEPOINT 2.00 5.00 POINT 1.07 2.20END OF OUTPUTSourceMid-Atlanta 1996 template is as follows: note * indicates that the cross product involves known intersections, cross-origin intersection of line segments [cpp] # include <cstdio> # include <cstring> # include <cmath> # include <cstdlib> # include <iostream> # include <algorithm> # include <functional> using namespace std; # define eps 1e-8 double sqr (double x) {return x * x;} struct P {double x, y; P (double _ x, double _ y ): x (_ x), y (_ y) {} P () {} double dis () {return sqrt (sqr (x) + sqr (y ));}}; struct V {double x, y; V (double _ x, double _ y): x (_ x), y (_ y) {} V (P a, P B): x (B. x-a.x), y. y-a.y) {}v () {}const double dis () {return sqrt (sqr (x) + sqr (y) ;}}; P operator + (const P, const V B) {return P (. x + B. x,. y + B. y);} V operator * (const double a, const V B) {return V (a * B. x, a * B. y);} double operator * (const V a, const V B) {return. x * B. y-b.x *. y;} P jiao_dian (const V a, V B, const V c, const v cd, const p c) {double d; d = B. dis (); double s1 = a * B, s2 = B * c; double k = s1/(s1 + s2); return C + k * CD ;} bool equal (const double a, const double B) {if (abs (a-B) <eps) return 1; return 0 ;}int n; int main () {// s freopen ("poj1269.in", "r", stdin); cout <"intersecting lines output" <endl; scanf ("% d", & n ); for (int I = 1; I <= n; I ++) {double x1, y1, x2, y2, x3, y3, x4, y4; scanf ("% lf", & x1, & y1, & x2, & y2, & x3, & y3, & x4, & y4); p a = P (x1, y1), B = P (x2, y2), C = P (x3, y3 ), D = P (x4, y4); v AB = V (A, B), AC = V (A, C), AD = V (A, D ), CD = V (C, D); if (equal (AB * CD), 0) {if (equal (AC * AD), 0 )) cout <"LINE \ n"; else cout <"NONE \ n";} else {P p = jiao_dian (AC, AB, AD, CD, C); cout. setf (ios: fixed); cout. precision (2); cout <"POINT" <p. x <''<p. y <endl ;}}cout <"end of output" <endl; 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.