Segments
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11593   Accepted: 3657

Description

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 x1 y1 x2 y2 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

3
2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3
0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3
0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0

Sample Output

Yes!
Yes!
No!

Source

【题意】

  给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!。
【思路】

  如果有存在这样的直线,过投影相交区域作直线的垂线,该垂线必定与每条线段相交,问题转化为问是否存在一条线和所有线段相交
  若存在一条直线与所有线段相机相交,此时该直线必定经过这些线段的某两个端点,所以枚举任意两个端点即可

【代码】

 #include<cmath>
#include<cstdio>
#include<cstring>
#define FOR(a,b,c) for(int a=(b);a<(c);a++)
using namespace std; const int N = +;
const double eps = 1e-; int dcmp(double x) {
if(x<eps) return ; else return x<? -:;
} struct Line {
double x1,y1,x2,y2;
}L[N]; int n; double cross(double x1,double y1,double x2,double y2,double x,double y) {
return (x2-x1)*(y-y1)-(x-x1)*(y2-y1);
}
bool judge(double x1,double y1,double x2,double y2) {
if(!dcmp(x2-x1) && !dcmp(y2-y1)) return ;
FOR(i,,n) {
if(cross(x1,y1,x2,y2,L[i].x1,L[i].y1)*
cross(x1,y1,x2,y2,L[i].x2,L[i].y2)>eps) return ;
}
return ;
} int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
FOR(i,,n)
scanf("%lf%lf%lf%lf",&L[i].x1,&L[i].y1,&L[i].x2,&L[i].y2);
if(n==) { puts("Yes!"); continue; }
bool ans=;
FOR(i,,n) {
FOR(j,i+,n) {
if(judge(L[i].x1,L[i].y1,L[j].x1,L[j].y1)) ans=;
if(judge(L[i].x1,L[i].y1,L[j].x2,L[j].y2)) ans=;
if(judge(L[i].x2,L[i].y2,L[j].x1,L[j].y1)) ans=;
if(judge(L[i].x2,L[i].y2,L[j].x2,L[j].y2)) ans=;
if(ans) break;
}
if(ans) break;
}
if(ans) puts("Yes!");
else puts("No!");
}
return ;
}

poj 3304 Segments(计算几何基础)的更多相关文章

  1. POJ 3304 Segments 判断直线和线段相交

    POJ 3304  Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...

  2. POJ 3304 Segments(计算几何:直线与线段相交)

    POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...

  3. POJ 3304 Segments(判断直线与线段是否相交)

    题目传送门:POJ 3304 Segments Description Given n segments in the two dimensional space, write a program, ...

  4. POJ 3304 Segments (判断直线与线段相交)

    题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...

  5. POJ 3304 Segments 基础线段交判断

    LINK 题意:询问是否存在直线,使得所有线段在其上的投影拥有公共点 思路:如果投影拥有公共区域,那么从投影的公共区域作垂线,显然能够与所有线段相交,那么题目转换为询问是否存在直线与所有线段相交.判断 ...

  6. poj 3304 Segments(计算直线与线段之间的关系)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10921   Accepted: 3422 Descrip ...

  7. POJ 3304 Segments (直线和线段相交判断)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 2316 Descript ...

  8. poj 3304 Segments

    Segments 题意:给你100以内的n条线段,问你是否存在一条直线,使得题给的线段在这条直线上的“投影” 相交于一点: 思路: 1.先要将线段投影相交于一点转变为存在一条直线与所有的线段相交: 很 ...

  9. 判断直线与线段相交 POJ 3304 Segments

    题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...

随机推荐

  1. References & the Copy-Constructor

    1 There are certain rules when using references: (Page 451) A reference must be initialized when it ...

  2. android程序的安装与卸载

    Android android在安装应用程序与卸载应用程序时都会发送广播,安装应用程序成功时会发送android.intent.action.PACKAGE_ADDED广播,可以通过intent.ge ...

  3. linux 信号处理

    查看信号 kill -l 信号实际就是一个进程发送给另一个进程的消息

  4. tomcat配置虚拟目录的步骤

    1.在tomcat中.....\conf\Catalina\localhost中创建一个test.xml文件 2.然后在\conf的server.xml中的 <Host > 元素里面 添加 ...

  5. php错误捕捉

    <?php //禁止错误输出 error_reporting(0); //设置错误处理器 set_error_handler('errorHandler'); register_shutdown ...

  6. 安装 SQL Server 2012 的硬件和软件要求(官方全面)

    以下各节列出了安装和运行 SQL Server 2012 的最低硬件和软件要求. 有关 SharePoint 集成模式下 Analysis Services 的要求的详细信息,请参阅硬件和软件要求(S ...

  7. python 函数1

    一.背景 在学习函数之前,一直遵循:面向过程编程,即:根据业务逻辑从上到下实现功能,其往往用一长段代码来实现指定功能,开发过程中最常见的操作就是粘贴复制,也就是将之前实现的代码块复制到现需功能处,如下 ...

  8. ubuntu杂记

    安装ssh: sudo apt-get install openssh-server sudo /etc/init.d/ssh start 将主机中vmware8的网络改为自动获取ip,就可以ping ...

  9. NET笔记——IOC详解和Unity基础使用介绍

    说起IOC,可能很多初学者不知道是用来做什么的,今天正好有点时间,就来扫扫盲,顺便巩固下自己. IOC全称是Inversion Of Control,意为控制反转(这些自然百度也有),可什么是控制反转 ...

  10. SDWebImage 原理及使用-b

    SDWebImage托管在github上.https://github.com/rs/SDWebImage 这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下 ...