poj3304计算几何直线与线段关系

时间:2022-05-26 02:00:42

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

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&colon;Area(计算几何,求线段与直线交点 &plus; 求多边形面积)

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

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

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

  3. 2017 ACM-ICPC乌鲁木齐网络赛 B&period; Out-out-control cars&lpar;计算几何 直线相交&rpar;

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

  4. Intersecting Lines---poj1269&lpar;求两直线的位置关系&rpar;

    题目链接: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&lpar;直线与线段相交&rpar;

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

随机推荐

  1. 计算机人物系列-Mauchly,Eckert,Goldstine

    关键词:莫尔学院(Moore School),阿伯丁试验场(Aberdeen Proving Ground), 雷明顿兰德公司(Remington Rand Corporation), IBM院士(I ...

  2. swift 如何获取webView的内容高度

    应用中如果使用webView,要想获取其内容高度,就要实现其代理方法, 首先添加代理UIWebViewDelegate 然后给代理赋值 webView.delegate = self 实现代理方法: ...

  3. HDU 2819 — Swap 二分匹配

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

  4. 【转】IPC-消息队列

    一.    概念 消息队列就是一个消息的链表.对消息队列有写权限的进程可以向其中按照一定的规则添加新消息:对消息队列有读权限的进程可以从消息队列中读出消息.消息队列是随内核持续的.下面介绍三个概念: ...

  5. MySQL源码 解析器

    sql请求发送到server端,需要经过解析器生成内部的数据结构对象,以方便进行优化和生成执行计划.解析器主要做了两件事情,词法分析和语法分析. 词法和语法分析:mysql使用lex词法分析器,yac ...

  6. android Json解析详解(详细代码)

    JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...

  7. 防xss攻击

    官方:https://jsxss.com/zh/index.html xss csrf https://www.cnblogs.com/443855539-wind/p/6055816.html 一. ...

  8. Python基础之集合

    一.定义: 二.基本操作: 三.运算: 交集&, 并集|, 补集-, 对称补集^, 子集<   超集> 四.集合推导式: 五.固定集合 frozenset 六.基本代码: # 1. ...

  9. 轮廓的查找、表达、绘制、特性及匹配&lpar;How to Use Contour&quest; Find&comma; Component&comma; Construct&comma; Features &amp&semi; Match&rpar;

    http://www.cnblogs.com/xrwang/archive/2010/02/09/HowToUseContour.html 作者:王先荣 前言    轮廓是构成任何一个形状的边界或外形 ...

  10. 【cs231n】图像分类笔记

    前言 首先声明,以下内容绝大部分转自知乎智能单元,他们将官方学习笔记进行了很专业的翻译,在此我会直接copy他们翻译的笔记,有些地方会用红字写自己的笔记,本文只是作为自己的学习笔记.本文内容官网链接: ...