POJ 1269 Intersecting Lines
来源:互联网 发布:浏览器运行js脚本 编辑:程序博客网 时间:2024/05/10 17:27
判断直线相交及求交点,可能会有斜率不存在的情况
#include <iostream>#include <cstdio>int main(){ double x1, y1, x2, y2, x3, y3, x4, y4; int n; double k1, k2; double b1, b2; double i_x, i_y; scanf("%d", &n); std::cout << "INTERSECTING LINES OUTPUT" << std::endl; while( n-- ) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); if( x1 != x2 && x3 != x4 ) { k1 = ( y2 - y1 ) / ( x2 - x1 ); k2 = ( y4 - y3 ) / ( x4 - x3 ); b1 = y1 - k1 * x1; b2 = y3 - k2 * x3; if( k1 == k2 ) { if( b1 == b2 ) printf("LINE\n"); else printf("NONE\n"); } else { i_x = (b2 - b1) / (k1 - k2); i_y = k1 * i_x + b1; printf("POINT %.2lf %.2lf\n", i_x, i_y); } } else if( x1 == x2 && x3 == x4 ) { if( x1 == x3 ) std::cout << "LINE\n"; else std::cout << "NONE\n"; } else if( x1 == x2 && x3 != x4 ) { k2 = ( y4 - y3 ) / ( x4 - x3 ); b2 = y3 - k2 * x3; i_x = x1; i_y = k2 * x1 + b2; printf("POINT %.2lf %.2lf\n", i_x, i_y); } else { k1 = ( y2 - y1 ) / ( x2 - x1 ); b1 = y1 - k1 * x1; i_x = x3; i_y = k1 * x3 + b1; printf("POINT %.2lf %.2lf\n", i_x, i_y); } } std::cout << "END OF OUTPUT\n"; return 0;}
- 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
- 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
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- OpenCV中调用cvCreateFileCapture函数返回NULL
- Leetcode: Subsets II
- 算法(第四版) Dijkstra 算数表达式求值算法-双栈
- 随笔二
- VIJOS-P1132(求先序遍历,已知中后)
- POJ 1269 Intersecting Lines
- 解决android sdk manager无法联网更新安装问题
- OpenCL中上下文
- (19) - 交通灯管理系统 (7k面试题)
- 一些小问题的解决办法(持续补充更新)
- POJ 2653 Pick-up sticks
- 面试时,你会问面试官哪些问题?
- 点击图片区域链接到另一页面
- OCP-1Z0-052-V8.02-30题