题意:判直线相交、平行、重合
吐槽:坑OJ,G++WA,C++AC,模版题
/************************************************Author :DarkTongCreated Time :2016/8/3 23:02:25File Name :Poj_1269.cpp*************************************************///#include#include #include #include using namespace std;#define eps 1e-9typedef long long LL;typedef double Db;struct Point{ Db x, y; Point(Db x=0, Db y=0):x(x), y(y){}}C;typedef Point Vector;//向量或点的四则运算Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y);}Vector operator - (Vector A, Vector B){ return Vector(A.x-B.x, A.y-B.y);}Vector operator * (Vector A, Db p){ return Vector(A.x*p, A.y*p);}Vector operator / (Vector A, Db p){ return Vector(A.x/p, A.y/p);}int dcmp(Db x){ if(fabs(x) 0(-90, 90), ==0(90或-90), <0((-180,90)或(90,180])*/Db Cross(Vector A, Vector B){ return A.x*B.y - A.y*B.x;} /*叉积(判<180的角): ==0(共线), >0(逆时针), <0(顺时针) */Point GetLineIntersection(Point P, Vector v, Point Q, Vector w){ Vector u = P-Q; double t = Cross(w, u)/Cross(v, w); //刚好时两个向量同向,所以不用取绝对值 return P+v*t;}/**************************************************************/Point poi[4];int main(){ int T, cas=1; scanf("%d", &T); puts("INTERSECTING LINES OUTPUT"); while(T--) { for(int i=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"); else puts("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;}