poj 3304 Segments 直线与线段
来源:互联网 发布:汽车电气设计软件 编辑:程序博客网 时间:2024/06/05 16:15
Segments
Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on it, all projected segments have at least one point in common.
Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case begins with a line containing a positive integer n ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1y1 x2 y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.
For each test case, your program must output "Yes!", if a line with desired property exists and must output "No!" otherwise. You must assume that two floating point numbers a and b are equal if |a - b| < 10-8.
321.0 2.0 3.0 4.04.0 5.0 6.0 7.030.0 0.0 0.0 1.00.0 1.0 0.0 2.01.0 1.0 2.0 1.030.0 0.0 0.0 1.00.0 2.0 0.0 3.01.0 1.0 2.0 1.0
Yes!Yes!No!
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<string>#include<stdlib.h>using namespace std;typedef long long ll;const double eps=1e-8;struct point{double xx,yy;point(double x=0,double y=0):xx(x),yy(y) {};};double Cross(point A,point B){ return A.xx*B.yy-A.yy*B.xx;}int dcmp(double x){ if(fabs(x)<eps)return 0; return x<0?-1:1;}point operator +(point A,point B) {return point(A.xx+B.xx,A.yy+B.yy); }point operator -(point A,point B) {return point(A.xx-B.xx,A.yy-B.yy); }point operator *(point A,double p) {return point(A.xx*p,A.yy*p); }point operator /(point A,double p) {return point(A.xx/p,A.yy/p); }bool operator ==(point A,point B) {return dcmp(A.xx-B.xx)==0&&dcmp(A.yy-B.yy)==0;} //-------------------------------------------------------------------------struct Rectangle{point p1;point p2;}a[105];int n;int judge(Rectangle t){if(t.p1==t.p2) return 0;//必须要判断两点是否重合。 for(int i=0;i<n;i++){point v1,v2,v3,v4;v1=a[i].p1-t.p1;v2=a[i].p1-t.p2;v3=a[i].p2-t.p1;v4=a[i].p2-t.p2;if(dcmp(Cross(v1,v2)*Cross(v3,v4))>0)//如果线段的两点在分别直线的两边,则线段与直线一定相交。 return 0;}return 1;}int main(){int T,flag;Rectangle t1,t2,t3,t4;scanf("%d",&T);while(T--){flag=0;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf",&a[i].p1.xx,&a[i].p1.yy,&a[i].p2.xx,&a[i].p2.yy);if(n==1) {puts("Yes!");continue;}//必须加 for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){t1.p1=a[i].p1;t1.p2=a[j].p1;t2.p1=a[i].p1;t2.p2=a[j].p2;t3.p1=a[i].p2;t3.p2=a[j].p1;t4.p1=a[i].p2;t4.p2=a[j].p2;//t5=a[i] 不需要加 if( judge(t1) || judge(t2) || judge(t3) || judge(t4) )flag=1;}}if(flag)printf("Yes!\n");elseprintf("No!\n");}return 0;}
- Poj 3304 Segments (直线与线段交)
- poj-3304-Segments-线段与直线相交
- poj 3304 Segments 线段与直线相交
- poj 3304 Segments 直线与线段
- POJ 3304 Segments (直线与线段相交)
- poj 3304 Segments(判断直线与线段相交)
- POJ 3304 Segments(判线段与直线相交)
- POJ 3304 Segments(计算几何:直线与线段相交)
- POJ 3304 Segments(直线与线段相交判定)
- POJ 3304 segments (直线与线段相交)
- POJ 3304 Segments 判断直线与线段相交
- poj 3304 Segments(线段与直线相交)
- poj 3304 Segments(贪心+直线是否与线段相交!)
- poj 3304 Segments 线段与直线的关系
- poj 3304Segments(直线与线段的相交关系)
- poj 3304 Segments(线段与直线相交)
- poj 3304 Segments--直线和线段相交
- POJ 3304 Segments(线段直线相交)
- OPC
- 顺序表&&单链表
- 自练题20170802
- 计算机网络--数据链路层
- 图像处理算法工程师
- poj 3304 Segments 直线与线段
- vue2.0分页
- [线段树] CodeChef Count on a Treap
- ROS / OpenCV Ubuntu安装“usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: 没有那个文件或目录”解决
- java
- 超全面的JavaWeb笔记day01<HTML等>
- 淘宝放大镜例子(js)
- 汉字显示方式一(FontCvt的使用)
- 七牛CEO许式伟:服务端开发那些事儿