Segments
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14178   Accepted: 4521

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 integern ≤ 100 showing the number of segments. After that, n lines containing four real numbers x1 y1 x2 y2 follow, in which (x1y1) and (x2y2) 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

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 103
#define N 21
#define MOD 1000000
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0);
/*
所有线段投射到给定线段上取交集,如果交集距离大于eps 存在!s
*/
int sgn(double x)
{
if (fabs(x) < eps) return ;
if (x < ) return -;
else return ;
}
struct Point
{
double x, y;
Point() {}
Point(double _x, double _y) :x(_x), y(_y) {}
Point operator - (const Point& r)const
{
return Point(x - r.x, y - r.y);
}
double operator ^(const Point& r)const
{
return x*r.y - y*r.x;
}
double operator * (const Point& r)const
{
return x*r.x + y*r.y;
}
};
double dist(Point a, Point b)
{
return sqrt((a - b)*(a - b));
}
struct Line
{
Point s, e;
Line() {}
Line(Point _a, Point _B) :s(_a), e(_B) {}
};
vector<Line> v;
bool Seg_inter_line(Line l1, Line l2)
{
return sgn((l2.s - l1.e) ^ (l1.s - l1.e))*sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= ;
}
bool check(Line l)
{
if (sgn(dist(l.s, l.e)) == )
return false;
for (int i = ; i < v.size(); i++)
if (!Seg_inter_line(l, v[i]))
return false;
return true;
}
int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
v.clear();
double x1, y1, x2, y2;
scanf("%d", &n);
for (int i = ; i < n; i++)
{
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
v.push_back(Line(Point(x1, y1), Point(x2, y2)));
}
bool f = false;
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
if (check(Line(v[i].s, v[j].s)) || check(Line(v[i].s, v[j].e))
|| check(Line(v[i].e, v[j].s)) || check(Line(v[i].e, v[j].e)))
{
f = true;
break;
}
}
}
if (f)
printf("Yes!\n");
else
printf("No!\n");
}
return ;
}

POJ 3304 segments 线段和直线相交的更多相关文章

  1. poj 3304 Segments 线段与直线相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K       Description Given n segments in the two dim ...

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

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

  3. POJ 3304 /// 判断线段与直线是否相交

    题目大意: 询问给定n条线段 是否存在一条直线使得所有线段在直线上的投影存在公共点 这个问题可以转化为 是否存在一条直线与所有的线段同时相交 而枚举直线的问题 因为若存在符合要求的直线 那么必存在穿过 ...

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

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

  5. POJ 3304 Segments | 线段相交

    #include<cstdio> #include<algorithm> #include<cstring> #define N 105 #define eps 1 ...

  6. POJ 3304 Segments(线的相交判断)

    Description Given n segments in the two dimensional space, write a program, which determines if ther ...

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

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

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

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

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

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

随机推荐

  1. 关于swoole 和golang 的压力测试结果

    一.环境介绍 linux centos7 php7.1.18 go1.12.1 2核4G内存 二.代码 swoole代码 <?php $http = new swoole_http_server ...

  2. css选择器---继承,优先级,层叠

    CSS三大特性—— 继承. 优先级和层叠. 继承:即子类元素继承父类的样式; 优先级:是指不同类别样式的权重比较; 层叠:是说当数量相同时,通过层叠(后者覆盖前者)的样式. css选择符分类 首先来看 ...

  3. skiing 暴力搜索 + 动态规划

    我的代码上去就是 直接纯粹的  暴力  .   居然没有超时   200ms  可能数据比较小   一会在优化 #include<stdio.h> #include<string.h ...

  4. ACM算法目录

    数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一 ...

  5. 【洛谷4158/BZOJ1296】[SCOI2009]粉刷匠(动态规划)

    题目:洛谷4158 分析: 这题一看就是动态规划. 可以看出,如果每个木条粉刷的次数是固定的,那么这些木条是互不干扰的,因此对于每个木条可以通过dp来求出把T次中的j次分配给这个木条时可以获得的最大正 ...

  6. [转]Linux rpm 命令参数使用详解

    转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html RPM是RedHat Package Mana ...

  7. 学习Objective-C入门教程(分享)

    原百度文库连接:http://wenku.baidu.com/view/6786064fe518964bcf847c63.html PS:需要原文档的可以留邮箱发送! (我叫雷锋,不要谢我) 学习Ob ...

  8. Java系列学习(二)-配置开发环境

    1.设置系统环境变量 1.1.设置JDK的Path路径 作用:通过path环境变量,将JDK安装目录下的bin目录配置到path变量下,可使javac指令和java指令在任意目录下运行   方法一:直 ...

  9. jenkinsfile or pipline 实现微服务自动发布回滚流程

    1 #!/usr/bin/env groovy Jenkinsfile node { //服务名称 def service_name = "**" //包名 def service ...

  10. jquery ajax在IE9以下进行跨域请求时无效的问题

    第一步:设置浏览器安全属性,启用[通过域访问数据源]选项: 1.选择Internet选项 2.选择安全---自定义级别 3.找到其他---通过域访问数据源,选择启用,然后确定就可以了. 第二步:调用a ...