poj 1269 Intersecting Lines 【直线相交】
来源:互联网 发布:c语言表白源代码 编辑:程序博客网 时间:2024/06/05 15:42
点击打开链接
题意:
给你两个条直线,判断两条直线的关系,
如果相交于一点,输出POINT 和该点坐标,
如果重合输出 LINE
如果平行输出 NONE
题解:
赤裸裸的判断两线相交,,
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<map>#include<cmath>#define x first#define y secondusing namespace std;const double eps=1e-8;const double PI=acos(-1.0);const int maxn=105;int sgn(double x){ if(fabs(x)<eps) return 0; if(x<0) return -1; return 1;}struct Point{ double x,y; Point(){} Point(double _x,double _y){ x=_x;y=_y; } Point operator -(const Point &b)const{ return Point(x-b.x,y-b.y); } double operator ^ (const Point &b)const{ return x*b.y - y*b.x; }};struct Line{ Point s,e; Line(){} Line(Point _s,Point _e){ s=_s;e=_e; } pair<int,Point> operator &(const Line &b)const{ Point res=s; if(sgn((s-e)^(b.s-b.e))==0){ if(sgn((s-b.e)^(b.s-b.e))==0) return make_pair(0,res); return make_pair(1,res); } double tt=((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e)); res.x+=(e.x-s.x)*tt; res.y+=(e.y-s.y)*tt; return make_pair(2,res); }};Point p1,p2,p3,p4;Line t1,t2;int main(){ int t,n,cnt; double x1,x2,x3,x4,y1,y2,y3,y4; scanf("%d",&t); puts("INTERSECTING LINES OUTPUT"); while(t--){ scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); p1={x1,y1};p2={x2,y2}; p3={x3,y3};p4={x4,y4}; t1={p1,p2};t2={p3,p4}; pair<int,Point>ans=t1&t2; if(ans.x==0) puts("LINE"); else if(ans.x==1) puts("NONE"); else { printf("POINT %.2f %.2f\n",ans.y.x,ans.y.y); } } puts("END OF OUTPUT");return 0;}
阅读全文
0 0
- 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(直线相交判断,求交点)
- 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 直线位置关系
- linux驱动
- 安装apr-util 执行make命令时报错的解决方法
- 非静态内部类
- 跨域问题和处理跨域的方法
- linux目录操作
- poj 1269 Intersecting Lines 【直线相交】
- 数论前奏-整数和mod
- 马的移动问题(国际象棋)
- 【题解】线性筛素数 线性统计范围质因数 小Y的智力游戏
- TI的开发资源
- Android 网络编程(一)HTTP协议
- 20170722日常总结
- SpringMVC接收页面表单参数
- stat查看文件属性