poj1269 Intersecting Lines
作者:互联网
题目描述:
题解:
直线判交没啥好说的……
(不要用g++,一定要用c++)
代码:
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const double eps = 1e-8; int dcmp(double x) { if(fabs(x)<=eps)return 0; return x>0?1:-1; } struct Point { double x,y; Point(){} Point(double x,double y):x(x),y(y){} Point operator +(const Point&a)const{return Point(x+a.x,y+a.y);} Point operator -(const Point&a)const{return Point(x-a.x,y-a.y);} Point operator *(const double&a)const{return Point(x*a,y*a);} double operator ^(const Point&a)const{return x*a.y-y*a.x;} }a,b,c,d; typedef Point Vector; struct Line { Point p; Vector v; Line(){} Line(Point p,Vector v):p(p),v(v){} }s1,s2; int n; void work() { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y); s1 = Line(a,b-a),s2 = Line(c,d-c); if(!dcmp(s1.v^s2.v)) { if(!dcmp(s1.v^(s2.p-s1.p)))puts("LINE"); else puts("NONE"); }else { double t = fabs(((s2.p-s1.p)^s2.v)/(s1.v^s2.v)); Point now = s1.p+s1.v*t; printf("POINT %.2lf %.2lf\n",now.x,now.y); } } int main() { puts("INTERSECTING LINES OUTPUT"); scanf("%d",&n); while(n--)work(); puts("END OF OUTPUT"); return 0; }View Code
标签:lf%,const,Point,double,poj1269,Lines,s2,Intersecting,s1 来源: https://www.cnblogs.com/LiGuanlin1124/p/10981489.html