poj 1269 Intersecting Lines
来源:互联网 发布:数控编程培训靠谱吗 编辑:程序博客网 时间:2024/06/17 06:27
题目链接:http://poj.org/problem?id=1269
题意:给你两条线段的两个端点,让你判断他们的情况,总共有三种情况,共线(NONE),平行(LINE),和相交(Point)
解析:共线和平行直接用斜率和叉乘来判断,剩下的就是求直线交点(推直线交点的时候心态别崩)
#include <cmath>#include <algorithm>#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <stack>using namespace std;const int maxn = 105+100;const double eps = 1e-8;struct point{ double x; double y; point() {} point(double _x,double _y) { x = _x; y = _y; }};struct line{ point a; point b;};double x_mul(point p0,point p1,point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool judge1(line l1,line l2){ //判断是否平行 double t1 = (l2.a.x-l2.b.x)*(l1.a.y-l1.b.y); double t2 = (l2.a.y-l2.b.y)*(l1.a.x-l1.b.x); return t1==t2;}//是否相交//bool judge2(line l1,line l2)//{// bool flag1 = min(l1.a.x,l1.b.x)<=max(l2.a.x,l2.b.x)&&// min(l1.a.y,l1.b.y)<=max(l2.a.y,l2.b.y)&&// min(l2.a.x,l2.b.x)<=max(l1.a.x,l1.b.x)&&// min(l2.a.y,l2.b.y)<=max(l1.a.y,l1.b.y);// bool flag2 = (x_mul(l1.a,l2.a,l2.b)*x_mul(l1.b,l2.a,l2.b)<=0)&&// (x_mul(l2.a,l1.a,l1.b)*x_mul(l2.b,l1.a,l1.b)<=0);// return flag1&&flag2;//}point cross(line l1,line l2){ point res; double t1 = x_mul(l1.a,l1.b,l2.a); double t2 = x_mul(l1.b,l1.a,l2.b); res.x = (l2.b.x*t1+l2.a.x*t2)/(t1+t2); res.y = (l2.b.y*t1+l2.a.y*t2)/(t1+t2); return res;}int main(void){ int n; cin>>n; puts("INTERSECTING LINES OUTPUT"); while(n--) { line l1,l2; scanf("%lf %lf %lf %lf",&l1.a.x,&l1.a.y,&l1.b.x,&l1.b.y); scanf("%lf %lf %lf %lf",&l2.a.x,&l2.a.y,&l2.b.x,&l2.b.y); if(judge1(l1,l2)) { if(x_mul(l1.a,l2.a,l2.b)) puts("NONE"); else puts("LINE"); } else { point ans = cross(l1,l2); printf("POINT %.2f %.2f\n",ans.x,ans.y); } } puts("END OF OUTPUT"); return 0;}
0 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
- angular 中的自定义指令之详解API
- 新世纪万年历
- 来来来 写一个二分查找 315. Count of Smaller Numbers After Self
- JNI详解---从不懂到理解
- 机器学习面试2
- poj 1269 Intersecting Lines
- HDU 1003
- Java反射机制详解
- 【经典智力题】1024! 末尾有多少个0?——“计算阶乘末尾0的数量”问题引出
- Android中使用动态代理模式
- Atitit需求文档模板大纲目录 attilax总结
- Spring-MVC框架下对web.xml文件及spring_mvc.xml文件内容的释义资料整理
- python的数学运算符
- vue2.0 中上传文件