poj3304计算几何直线与线段关系
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计算几何直线与线段关系的更多相关文章
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- TOYS(计算几何基础+点与直线的位置关系)
题目链接:http://poj.org/problem?id=2318 题面: TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- 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 ...
- Intersecting Lines---poj1269(求两直线的位置关系)
题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- 判断直线与线段相交 POJ 3304 Segments
题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...
- poj 3304(直线与线段相交)
传送门:Segments 题意:线段在一个直线上的摄影相交 求求是否存在一条直线,使所有线段到这条直线的投影至少有一个交点 分析:可以在共同投影处作原直线的垂线,则该垂线与所有线段都相交<==& ...
随机推荐
- VC++中解决“在查找预编译头使用时跳过”的方法
Visual C++ Concepts: Building a C/C++ ProgramCompiler Warning (level 1) C4627Error Message": sk ...
- 带金属光泽的模型shader的实现
最近捣鼓了一下金属光泽的shader的实现,在一些高模展示的时候或者模型的金属部分的表现的时候,我们需要给模型添加一些金属光泽,表现出一个模型某些金属装备上有一定的反光.今天我主要写一种基于贴图实现的 ...
- 【树莓派】制作树莓派最小镜像:img裁剪瘦身
制作树莓派镜像,可以参考这篇文章:http://blog.csdn.net/talkxin/article/details/50456282 摘录部分要点内容如下(如果作者不允许转载,请联系即删除): ...
- SLF4J 的几种实际应用模式--之三:JCL-Over-SLF4J+SLF4J
我们前面已经讲过了 SLF4J 的两种用法:SLF4J+Log4J 和 SLF4J+Logback,那是在比较理想的情况下,所用组件只使用了 SLF4J 这一种统一日志框架的时候.可是 JCL 一直 ...
- Android开发之自定义视图
继承View 1.重写onMeasure(int wMeasureSpec,int hMeasureSpec)处理程序,这样可以标明视图尺寸 2.重写onDraw,以便绘制我们自己的自定义视图内 3. ...
- 实验楼-1-Hello world!
初识实验楼,决定在上面好好的练练手. Course 1 : print "Hello world" 在虚拟机桌面,打开终端Xfce,通过运行linux指令,新建c文件,进行编辑,编 ...
- SharePoint JavaScript 客户端对象使用视频教程
本次视频教程是为大家介绍如何使用SharePoint JavaScript客户端对象,包括对于站点.列表.文档库.列表项.文件夹.文件和附件等基本对象的操作,同时,为大家举几个简单的应用的例子,让大家 ...
- artemplate使用
最近写了一个菜谱展示的网页,其中用到了artemplate模板,关于artemplate的好处就不多说了,直接上干货 1. <script src="js/template-nativ ...
- sass ruby环境 安装配置,使用sublime text3 中sass
首先,你想要使用sass的话,就必须依赖于ruby环境.所以,你要下一个ruby.具体的链接应该是(http://rubyinstaller.org/downloads).下载相应的版本.- 下载好之 ...
- STM32位带操作总结---浅显易懂
正在准备做毕业设计,配置LED_Config()的时候,又看到了位带操作的宏定义,我又嘀咕了,什么是位带操作,一年前在使用位带操作的时候,就查阅过好多资料,Core-M3也看过,但是对于博主这种“低能 ...