//以下为原blog搬迁过来的内容
【题目大意】:给出n组数据,每组数据四个数描述两条直线,判断直线重合,平行,或者相交。
【解题思路】:按照重合,平行,相交的顺序依次判断就是。主要是为了测试计算几何模版
【代码】:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cctype>
#include <map>
#include <iomanip>
using namespace std;
#define eps 1e-8
#define pi acos(-1.0)
#define inf 1<<30
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long
struct Point
{
double x,y;
Point() {}
Point (double a,double b)
{
x=a,y=b;
}
}point[8];
struct Line
{
Point a,b;
Line() {}
Line(Point x,Point y)
{
a=x,b=y;
}
}line[2];
inline int sig(double k) {
return k < -eps ? -1 : k > eps;
}
inline double det(double x1, double y1, double x2, double y2)
{
return x1 * y2 - x2 * y1;
}
inline double xmult(Point o, Point a, Point b)
{
return det(a.x - o.x, a.y - o.y, b.x - o.x, b.y - o.y);
}
void getline(const Point &x, const Point &y, double &a, double &b, double &c)
{
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
}
inline bool parallel(Line u,Line v)
{
return sig((u.a.x-u.b.x)*(v.a.y-v.b.y)-(v.a.x-v.b.x)*(u.a.y-u.b.y))==0;
}
inline bool sameline(Line u,Line v)
{
if (sig(xmult(u.a,v.a,v.b))==0 && sig(xmult(u.b,v.a,v.b))==0)
return true;
else return false;
}
Point intersect(double a1, double b1, double c1, double a2, double b2, double c2)
{
Point ret;
ret.y = (a1 * c2 - c1 * a2) / (b1 * a2 - a1 * b2);
if (sig(a2) == 0) ret.x = -(b1 * ret.y + c1) / a1;
else ret.x = -(b2 * ret.y + c2) / a2;
return ret;
}
int main()
{
int T;
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while (T--)
{
double p,q;
for (int i=0; i<=3; i++)
{
scanf("%lf%lf",&p,&q);
point[i]=Point(p,q);
}
line[0]=Line(point[0],point[1]);
line[1]=Line(point[2],point[3]);
double a1,a2,b1,b2,c1,c2;
getline(line[0].a,line[0].b,a1,b1,c1);
getline(line[1].a,line[1].b,a2,b2,c2);
if (sameline(line[0],line[1])==true) printf("LINE\n");
else
{
if (parallel(line[0],line[1])==true) printf("NONE\n");
else
{
Point p1;
p1=intersect(a1,b1,c1,a2,b2,c2);
printf("POINT %.2lf %.2lf\n",p1.x,p1.y);
}
}
}
printf("END OF OUTPUT\n");
return 0;
}