POJ 1269 Intersecting Lines(直线相交判断,求交点)
来源:互联网 发布:数据库添加数据 编辑:程序博客网 时间:2024/05/19 02:05
题意 : 就是让你求直线是否相交,若相交求出交点
题解 :先要有一个意识就是求直线方程不是很麻烦,我就是被这个给坑了,会求直线方程这个问题就解决了 剩下的就是解方程了 (注意斜率不存在的情况就好了)
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cmath>using namespace std;//const double eps = 1e-8;const int maxn = 15;const double eps = 1e-8;struct line { double x1,y1,x2,y2;}L[maxn];int n;double corss (double x1,double y1,double x2,double y2) { return x1 * y2 - x2 * y1;}void solve (line a,double & k,double & b) { int x1 = a.x1,x2 = a.x2,y1 = a.y1,y2 = a.y2; k = (y1 - y2) / (double) (x1 - x2); b = y2 - k * x2;}int main () { ios_base :: sync_with_stdio(false); cin >> n; double k1,k2,b1,b2,px,py; cout << "INTERSECTING LINES OUTPUT" << endl; for (int i = 1;i <= n; ++ i) { cin >> L[1].x1 >> L[1].y1 >> L[1].x2 >> L[1].y2; cin >> L[2].x1 >> L[2].y1 >> L[2].x2 >> L[2].y2; if (fabs(corss (L[1].x2 - L[1].x1,L[1].y2 - L[1].y1,L[2].x2 - L[2].x1,L[2].y2 - L[2].y1)) < eps) { if (fabs(corss(L[1].x1 - L[2].x1,L[1].y1 - L[2].y1,L[1].x1 - L[2].x2,L[1].y1 - L[2].y2)) < eps) { cout << "LINE" << endl; } else { cout << "NONE" << endl; } } else { cout << "POINT" << ' '; if (fabs(L[1].x1 - L[1].x2) < eps) { solve(L[2],k2,b2); px = L[1].x1; py = k2 * px + b2; printf ("%.2f %.2f",px,py); } else if (fabs(L[2].x1 - L[2].x2) < eps) { solve(L[1], k1, b1); px = L[2].x1; py = k1 * px + b1; printf ("%.2f %.2f",px,py); } else { solve(L[1], k1, b1); solve(L[2], k2, b2); px = (b1 - b2) / double (k2 - k1); py = k1 * px + b1; printf ("%.2f %.2f",px,py); } cout << endl; } } cout << "END OF OUTPUT"; return 0;}
阅读全文
0 0
- poj 1269 Intersecting Lines(判断直线相交 求交点)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- poj 1269 Intersecting Lines(直线相交判断,求相交交点)
- poj 1269Intersecting Lines (直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- Intersecting Lines(直线相交判断,求相交交点)
- poj 1269 Intersecting Lines(判断线段相交,并求交点)
- POJ 1269 Intersecting Lines 判断直线相交
- POJ 1269Intersecting Lines 直线相交判断
- 判断两条直线 共线或 平行 或相交 求交点 叉乘的应用 poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines(直线相交?平行?重合?,求交点)
- poj 1269 Intersecting Lines 计算几何 直线求交点
- poj 1269 Intersecting Lines (求直线交点)
- POJ 1269 Intersecting Lines 求两直线交点
- POJ 1269 Intersecting Lines 叉积(求直线交点)
- POJ 1269 Intersecting Lines(判断直线相交)
- POJ 1269 Intersecting Lines(直线相交的判断)
- hdu1025 Constructing Roads In JGShining's Kingdom
- goLang中的基础类型简单应用
- HDU 2415 树形DP
- ZOJ
- gulp 给静态资源文件添加hash(md5)后缀 防止缓存
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- 【cc3200】向服务器发送温度数据
- 数据分析(第一天)
- CSS+div
- 英特尔—最大区间
- 今天复习了一下Java基础
- JAVA Spring web mvc 学习 之 4:注解
- numpy中的ndarray与array的区别、不同
- hdu 1250 大数