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!
一开始看不懂题意只好搜题意,看懂了题意之后还是花了两个多小时wa了七遍,只好看题解,可能是精度的地方写搓了>.<坑爹啊
叉积判断线段的两端点是不是在直线的两侧
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; struct point{
double x,y;
};
struct line{
point a,b;
}l[N]; int n;
double mul(point p,point u,point v)
{
return (u.x-v.x)*(p.y-u.y)-(u.y-v.y)*(p.x-u.x);
}
bool ok(point u,point v)
{
if(fabs(u.x-v.x)<eps&&fabs(u.y-v.y)<eps)return ;
for(int i=;i<n;i++)
if(mul(l[i].a,u,v)*mul(l[i].b,u,v)>=eps)
return ;
return ;
}
int main()
{
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=;i<n;i++)
cin>>l[i].a.x>>l[i].a.y>>l[i].b.x>>l[i].b.y;
if(n<=)
{
cout<<"Yes!"<<endl;
continue;
}
bool flag=;
for(int i=;i<n&&!flag;i++)
{
if(ok(l[i].a,l[i].b))flag=;
for(int j=i+;j<n&&!flag;j++)
if(ok(l[i].a,l[j].a)||ok(l[i].a,l[j].b)||ok(l[i].b,l[j].a)||ok(l[i].b,l[j].b))
flag=;
}
if(flag)cout<<"Yes!"<<endl;
else cout<<"No!"<<endl;
}
return ;
}

poj3304计算几何直线与线段关系的更多相关文章

  1. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. TOYS(计算几何基础+点与直线的位置关系)

    题目链接:http://poj.org/problem?id=2318 题面: TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  3. 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)

    题目描述 Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenu ...

  4. Intersecting Lines---poj1269(求两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...

  5. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

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

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

  7. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

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

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

  9. poj 3304(直线与线段相交)

    传送门:Segments 题意:线段在一个直线上的摄影相交 求求是否存在一条直线,使所有线段到这条直线的投影至少有一个交点 分析:可以在共同投影处作原直线的垂线,则该垂线与所有线段都相交<==& ...

随机推荐

  1. 'utf8' codec can't decode byte 0xd1 in position 931: invalid continuation byte解决方法

    有时候,我得到这样的字符œ导致的UnicodeDecodeError错误. 我需要能够使串的UTF-8有或没有这些字符. 在工作中,经常遇到,读取一个文件,或者是从网页获取一个问题,明明看着是gb23 ...

  2. ASP.NET使用ajax实现分页局部刷新页面

    listview列表实现分页是非常容易的.ListView分页是非常简单的,加上一个DataPager控件,把ListView的ID赋予就可以了.最开始我就是这么写的.(网上有人说这样是伪分页?) & ...

  3. JAVA-Servlet-ServletConfig 与 ServletContext 的区别

    什么是ServletConfig? Servlet容器初始化一个servlet对象时,会为这个servlet对象创建一个servletConfig对象.在servletConfig对象中包含了serv ...

  4. java学习笔记 --- 异常

    异常 (1)程序出现的不正常的情况. (2)异常的体系   Throwable    |--Error  错误,严重问题,我们不处理.    ·    |--Exception 异常     |--R ...

  5. WebService从服务端到客户端的用例

    1.首先编写Wsdl(基于契约优先的方式),要注意的是命名空间(若是使用include或import)最好使用一致的,代码如下: <?xml version="1.0" en ...

  6. oracle事物总结(转)

    关于Oracle事务的总结 1.什么是事务,事务的特性是什么? 事务的任务便是使数据库从一种状态变换成为另一种状态,这不同于文件系统,它是数据库所特用的.它的特性有四个:TOM总结为ACID即原子性a ...

  7. cent os 直接访问谷歌的脚本实现

    https://github.com/DingGuodong/GoogleHostsFileForLinux/blob/master/replaceLocalHostsFileAgainstGfw.s ...

  8. javaweb浏览器随机输出一张验证码图片

    一.在web.xml中的配置如下: <?xml version="1.0" encoding="UTF-8"?><web-app xmlns: ...

  9. POPTEST老李分享session,cookie的安全性以及区别 2

    四,session和cookie谁更安全 就个人而言,我觉得session更安全一点,我以下几点看法. 1,如果session和cookie一样安全的话,二者就没有并要同时存在了,只要cookie就好 ...

  10. 4.Java集合总结系列:Map接口及其实现

    一.Map接口 Map集合的特点是:通过key值找到对应的value值,key值是唯一的,value可以重复.Map中的元素是无序的,但是也有实现了排序的Map实现类,如:TreeMap. 上面Map ...