poj3304 Segments
来源:互联网 发布:mac 找不到原始项目 编辑:程序博客网 时间:2024/05/16 12:49
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
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 x1y1x2y2 follow, in which (x1, y1) and (x2, y2) are the coordinates of the two endpoints for one of the segments.
Output
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.
Sample Input
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
Sample Output
Yes!Yes!No!
题意:问你是有存在一条线和n条线都有交点
思路:如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,
若存在一条直线与所有线段相机相交,此时该直线必定经过这些线段的某两个端点,所以枚举任意两个端点即可。#include<iostream>#include<cstdio>#include<cmath>using namespace std;const double eps=1e-8;bool f;int n;struct point {double x,y;};struct vector{point start,end;};point p;vector line[1000];double multi(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool fun(point a,point b){if(fabs(a.x-b.x)<eps&&fabs(a.y-b.y)<eps)return false;for(int i=0;i<n;i++){if(multi(line[i].start,a,b)*multi(line[i].end,a,b)>eps)return false;}return true;}int main(){int t;cin>>t;while(t--){f=false;cin>>n;for(int i=0;i<n;i++)cin>>line[i].start.x>>line[i].start.y>>line[i].end.x>>line[i].end.y;if(n<3)f=true;for(int i=0;i<n&&!f;i++){//if(fun(line[i].end,line[i].start))//f=true;for(int j=i+1;j<n&&!f;j++)if(fun(line[i].start,line[j].end)||fun(line[i].end,line[j].start)||fun(line[i].end,line[j].end)||fun(line[i].start,line[j].start))f=true;}if(!f)printf("No!\n");elseprintf("Yes!\n");}return 0; }
- POJ3304 Segments
- poj3304 - Segments
- POJ3304-Segments
- poj3304 Segments
- POJ3304--Segments
- Poj3304 Segments
- poj3304 Segments
- POJ3304 Segments
- POJ3304 Segments
- [poj3304]:Segments
- 【计算几何】 poj3304 Segments
- poj3304—Segments
- [POJ3304]Segments(计算几何)
- poj3304 Segments(计算几何+直线相交)
- Segments(poj3304,判断线段与直线相交)
- ACM-计算几何之Segments——poj3304
- poj3304-Segments-判断直线和线段是否相交
- poj3304-Segments 是否存在直线经过所有线段
- 几种软负载均衡策略分析
- Android多媒体详解
- Oracle学习笔记(十)——分页显示简单示例
- Java二叉树(二)--根据前序和中序遍历求后序遍历
- 直线拟合算法(续)
- poj3304 Segments
- Integer的秘密
- 安装mysql提示3306端口已经被占用解决方案
- Android Studio报错:Ignoring unknown package filter 'build-tools-23.0.0-preview'Warning:
- hadoop生态系统学习之路(十一)Zookeeper的简单使用
- 服务器启用了TRACE Method如何关闭?
- 四、s3c2440 裸机开发 通用异步收发器UARN
- Atitit.vod 视频播放系统 影吧系统的架构图 架构体系 解决方案
- 完全教程 Aircrack-ng破解WEP、WPA-PSK加密利器 [MARK]