一、传送门
http://poj.org/problem?id=1269
二、算法分析说明
三、代码
#include<cstdio>
#include<cmath>
#pragma warning(disable:4996)
template<class _Ty> struct point { _Ty x, y; };
unsigned n; point<double> a, b, c, d; double s1, s2, k;
template<class _Ty> inline _Ty cross_product(const _Ty& x1, const _Ty& y1, const _Ty& x2, const _Ty& y2) {
return x1 * y2 - x2 * y1;
}
template<class _Ty> inline _Ty cross_product(const point<_Ty>& a, const point<_Ty>& b, const point<_Ty>& c, const point<_Ty>& d) {//cross product ab×cd
return (b.x - a.x) * (d.y - c.y) - (d.x - c.x) * (b.y - a.y);
}
int main() {
scanf("%u", &n); ++n; puts("INTERSECTING LINES OUTPUT");
while (--n) {
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);
if (cross_product(a, b, c, d) == 0) {
if (cross_product(a, b, a, c) == 0) { puts("LINE"); continue; }
puts("NONE"); continue;
}
s1 = cross_product(a, c, d, c); s2 = cross_product(d, c, b, c); k = s1 / (s1 + s2);
printf("POINT %.2lf %.2lf\n", a.x + k * (b.x - a.x), a.y + k * (b.y - a.y));
}
puts("END OF OUTPUT");
return 0;
}