POJ 1269直线相交
来源:互联网 发布:matlab矩阵的取值 编辑:程序博客网 时间:2024/06/05 18:36
题目:题目链接
题目意思:就是给你两条直线的上的两点的坐标,让你判断这两条直线是不是相交,不相交的话判断是不是平行或者是不是重合。分别输出“NONE”和“LINE”
分析:这道题目只要细心就可以过的。对两条直线的斜率进行分情况判断。分别带入就行。看代码就明白了:
#include <iostream>#include <cstdio>#include <string>#include <string.h>#include <map>#include <vector>#include <cstdlib>#include <cmath>#include <algorithm>#include <queue>#include <set>#include <stack>using namespace std;int main(){ int t; double x1,y1,x2,y2,x3,y3,x4,y4; scanf("%d", &t); printf("INTERSECTING LINES OUTPUT\n"); while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); if(x1==x2 && x3==x4)//两直线都没有斜率 { if(x3==x1) printf("LINE\n"); else printf("NONE\n"); } else if(x1==x2 && x3!=x4)//有一条直线斜率存在 { double k = (y4-y3)*1.0/(x4-x3); double b = y3-(k*x3); double ansx = x1; double ansy = k*x1+b; printf("POINT %.2lf %.2lf\n", ansx, ansy); } else if(x1!=x2 && x3==x4)//有一条直线斜率存在 { double k = (y2-y1)*1.0/(x2-x1); double b = y2-(k*x2); double ansx = x3; double ansy = k*x3+b; printf("POINT %.2lf %.2lf\n", ansx, ansy); } else //两条直线斜率都存在 { double k1 = (y2-y1)*1.0/(x2-x1); double b1 = y2-(k1*x2); double k2 = (y4-y3)*1.0/(x4-x3); double b2 = y3-(k2*x3); if(k1==k2) { if(b1==b2) printf("LINE\n"); else printf("NONE\n"); } else { double ansx = (b1-b2)*1.0/(k2-k1); double ansy = k1*ansx + b1; printf("POINT %.2lf %.2lf\n", ansx, ansy); } } } printf("END OF OUTPUT\n"); return 0;}
就是这样的判断,这样可以完全包含各种情况了。
nlnl...
- POJ 1269直线相交
- POJ 1269 判断直线与直线相交
- poj 1269 Intersecting Lines--直线相交
- POJ 1269 直线相交(水题请绕行~~~~~)
- POJ 1269 Intersecting Lines 判断直线相交
- POJ 1269Intersecting Lines 直线相交判断
- poj 1269 Intersecting Lines 【直线相交】
- POJ 1269(计算几何+直线相交)
- POJ 2074 直线相交
- poj 1269 知识点:直线相交判断,求相交交点
- POJ 1039Pipe(直线相交)
- poj 1269 Intersecting Lines(判断直线相交 求交点)
- POJ - 1269:Intersecting Lines__判断两直线相交
- poj 1269 判断直线相交,并求交点
- POJ-1269 直线相交的判断及交点
- POJ 1269 Intersecting Lines(判断直线相交)
- POJ 1269 Intersecting Lines(直线相交的判断)
- POJ 1269 || Intersecting Lines(直线重合,平行,相交判定
- 敏捷的价值
- java获取当天的开始时间,当前周的开始时间
- 【Android内存机制分析】了解Android堆和栈
- 添加sudo用户
- ASIHTTPRequest-进度追踪
- POJ 1269直线相交
- PHP setcookie无效的原因分析
- ActionBarSherlock组件。
- Amlogic修改LCD亮度最小值与去掉设置---平板电脑---系统更新
- C++ 异常处理 catch(...)
- 贪心 CF 332 C 好题 赞
- JSON学习
- ASIHttpRequest学习笔记(1):创建队列、下载请求、断点续传、解压缩
- This solution contains no resources scoped for a Web application and cannot be deployed to a .....