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)