POJ 1269 直线相交(水题请绕行~~~~~)
2014-03-26 09:53
357 查看
题目链接:http://poj.org/problem?id=1269
题解:贴上来 只是想说 水题也是有尊严的0.0 好吧我下次不贴了……
题解:贴上来 只是想说 水题也是有尊严的0.0 好吧我下次不贴了……
#include<cstdio> #include<cmath> //定义点 struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} }; typedef Point Vector; //Vector 为 Point的别名 //向量+向量=向量 点+向量=点 Vector operator + (Vector A, Vector B) {return Vector(A.x+B.x, A.y+B.y);} //点-点=向量 Vector operator - (Point A, Point B) {return Vector(A.x-B.x, A.y-B.y);} //向量*数=向量 Vector operator * (Vector A, double p) {return Vector(A.x*p, A.y*p);} //向量/数=向量 Vector operator / (Vector A, double p) {return Vector(A.x/p, A.y/p);} //叉积:两向量v和w的叉积等于v和w组成的三角形的有向面积的两倍 XaYb - XbYa double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; } //两直线交点 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; } int main () { printf("INTERSECTING LINES OUTPUT\n"); int T; scanf("%d", &T); while(T--) { Point A, B, C, D; 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(A.x == B.x && C.x == D.x) //无斜率 垂直于X轴 { if(A.x == C.x) //同一条直线 printf("LINE\n"); else printf("NONE\n"); continue; } double k1 = (B.y-A.y)/(B.x-A.x), k2 = (D.y-C.y)/(D.x-C.x); if(k1 == k2) //斜率相同 { if(D.y == k1*D.x + A.y - k1*A.x) //在同一条直线上 printf("LINE\n"); else printf("NONE\n"); continue; } Point ans = GetLineIntersection(A, A-B, C, C-D); printf("POINT %.2lf %.2lf\n", ans.x, ans.y); } printf("END OF OUTPUT\n"); return 0; }
相关文章推荐
- poj 1269 判断直线相交,并求交点
- POJ 1269 Intersecting Lines 直线相交判断
- POJ 1269直线相交
- POJ 1269 Intersecting Lines(直线相交?平行?重合?,求交点)
- poj 1269 直线相交情况
- POJ 1269 Intersecting Lines(判断直线相交)
- POJ 1269 || Intersecting Lines(直线重合,平行,相交判定
- POJ 1269(计算几何+直线相交)
- Intersecting Lines(poj1269,判断直线与直线相交)
- POJ 1269 Intersecting Lines(线段相交,水题)
- poj 1269 知识点:直线相交判断,求相交交点
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- POJ 1269 判断直线的关系:相交,平行,重合
- poj 1269 Intersecting Lines(直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- POJ 1269 判断直线与直线相交
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- POJ-1269 直线相交的判断及交点
- poj 1269Intersecting Lines (直线相交判断,求相交交点)
- POJ1269---Intersecting Lines (计算几何基础:直线相交求交点)