poj_1269 intersecting Lines-Two straight line status (water problem, pit OJ)

Source: Internet
Author: User

Test instructions: line intersection, parallel, coincident

Spit Groove: Pit Oj,g++wa,c++ac, template problem

/************************************************author:D arktongcreated time:2016/8/3 23:02:25File Name:P oj_1269.cpp*************************************************///#include <bits/stdc++.h>#include <cstdio>#include<cstring>#include<cmath>using namespacestd;#defineEPS 1e-9typedefLong LongLl;typedefDoubleDb;structpoint{Db x, y; Point (Db x=0, Db y=0): X (x), Y (y) {}}c;typedef point Vector;//arithmetic of a vector or pointVectoroperator+ (vector A, vector B) {returnVector (a.x+b.x, a.y+b.y);} Vectoroperator-(vector A, vector B) {returnVector (a.x-b.x, a.y-b.y);} Vectoroperator* (Vector A, Db p) {returnVector (A.x*p, a.y*p);} Vectoroperator/(Vector A, Db p) {returnVector (a.x/p, a.y/p);}intDCMP (Db x) {if(Fabs (x) <eps)return 0;Else returnx<0? -1:1;} Db Dot (vector A, vector B) {returna.x*b.x + a.y*b.y;}/*dot Product: Angular distribution: >0 (-90, 90), ==0 (90 or -90), <0 (( -180,90) or (90,180])*/Db Cross (vector A, vector B) {returna.x*b.y-a.y*b.x;}/*cross product (<180 angle): ==0 (collinear), >0 (counterclockwise), <0 (clockwise)*/Point getlineintersection (point P, Vector v, point Q, vector w) {vector u= Pp; Doublet = Cross (w, u)/cross (V, W);//just two vectors in the same direction, so you don't have to take absolute values.    returnp+v*t;}/**************************************************************/Point poi[4];intMain () {intT, cas=1; scanf ("%d", &T); Puts ("intersecting LINES OUTPUT");  while(t--)    {         for(intI=0;i<4; ++i) scanf ("%LF%LF", &poi[i].x, &poi[i].y); Vector v1= poi[1]-poi[0], V2 = poi[3]-poi[2]; if(DCMP (Cross (v1, v2)) = =0)        {            if(DCMP (Cross (poi[0]-poi[2], v1) = =0) puts (" Line"); ElsePuts"NONE"); }        Else{point T= Getlineintersection (poi[0], v1, poi[2], v2); printf ("Point %.2lf%.2lf\n", T.x, T.Y); }} puts ("END of OUTPUT"); return 0;}

poj_1269 intersecting Lines-Two straight line status (water problem, pit OJ)

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.