原题传送门:http://poj.org/problem?id=3304
博主的中文题面(数据水):
https://www.luogu.org/problemnew/show/T22834

Segments

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| < 1e-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!

题目大意

问是否有一条能与平面内所有线段相交的直线

题解

英文题面的直接意思并不是中文题面那样直接明了,具体的证明大家自己用几何画板做做垂线感性证明一下吧。。。因为一定能找到一条满足题意的直线使其过线段中的某两个端点(感性理解)。所以,我们只需要O(n^2)枚举所有端点,O(n)挨个检验这条直线与所有线段的交点即可水过。

代码
#include<cstdio>
#include<cstring>
#define db double
using namespace std;
const int M=105;
const db eps=1e-8;
struct pt{db x,y;};
struct li{pt f,t;};
db operator * (pt a,pt b){return a.x*b.y-a.y*b.x;}
pt operator - (pt a,pt b){return (pt){a.x-b.x,a.y-b.y};}
int sig(db a){return (a>eps)-(a<-eps);}
int n,top;
pt pp[M<<1];
li ll[M];
void in()
{db a,b,c,d;scanf("%d",&n);for(int i=1;i<=n;++i){scanf("%lf%lf%lf%lf",&a,&b,&c,&d);pp[++top]=(pt){a,b};pp[++top]=(pt){c,d};ll[i]=(li){pp[top],pp[top-1]};}
}
db area(pt a,pt b,pt c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
int test(pt a,pt b,pt c,pt d)
{int d1=sig(area(a,b,c));int d2=sig(area(a,b,d));if((d1^d2)==-2) return 1;if(d1==0||d2==0) return 2;return 0;
}
bool check(pt a,pt b)
{if(!sig(a.x-b.x)&&!sig(a.y-b.y)) return 0;for(int i=1;i<=n;++i)if(test(a,b,ll[i].f,ll[i].t)==0) return 0;return 1;
}
void ac()
{bool flag=0;for(int i=1;i<top;++i)for(int j=i+1;j<=top;++j)if(check(pp[i],pp[j])) {flag=1;break;}if(flag) printf("Yes!\n");else printf("No!\n");
//  for(int i=1;i<=top;++i)
//  printf("%lf %lf\n",pp[i].x,pp[i].y);memset(pp,0,sizeof(pp));memset(ll,0,sizeof(ll));top=0;
}
int main()
{int T;scanf("%d",&T);for(int i=1;i<=T;++i)in(),ac();return 0;
}

POJ3304 Segments相关推荐

  1. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

  2. codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)

    题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  3. R语言使用ggpubr包的ggdotplot函数可视化水平棒棒糖图(自定义分组数据点色彩、自定义调色板、在两端添加点图的线段segments、整体排序从大到小、自定义数据点的大小、添加数值标签)

    R语言使用ggpubr包的ggdotplot函数可视化水平棒棒糖图(自定义分组数据点色彩.自定义调色板.在两端添加点图的线段segments.整体排序从大到小.自定义数据点的大小.添加数值标签) 目录

  4. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线

    D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...

  5. 关于Uri.Segments 属性的理解

    public string[] Segments { get; } Segments 属性返回一个字符串数组,该数组包含构成 URI 的绝对路径的"段"(子字符串).通过分析绝对路 ...

  6. lucene正向索引——正向信息,Index – Segments (segments.gen, segments_N) – Field(fnm, fdx, fdt) – Term (tvx, ...

    转自:http://www.cnblogs.com/forfuture1978/archive/2009/12/14/1623599.html 上面曾经交代过,Lucene保存了从Index到Segm ...

  7. PAT甲级1104 Sum of Number Segments:[C++题解]数段之和,测试点2爆double,请用long double!!!

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:本题题意比较简单,但是不能仅仅根据定义来算. 本题思路:统计每个数在多少个区间出现过,也就是这个数需要加多少次.共有n个数,其中第i个 ...

  8. poj 1436 zoj 1391 Horizontally Visible Segments (Segment Tree)

    ZOJ :: Problems :: Show Problem 1436 -- Horizontally Visible Segments 用线段树记录表面能被看见的线段的编号,然后覆盖的时候同时把能 ...

  9. 翻译: Oralce官方文档-- Data Blocks, Extents, and Segments

    Data Blocks, Extents, and Segments                                                                   ...

  10. oracle 12c undo,Oracle 12C新特性-临时UNDO段(Temporary Undo Segments) | 信春哥,系统稳,闭眼上线不回滚!...

    在12C版本,为了减少UNDO表空间的使用率及减少REDO和归档日志的产生量,ORACLE推出了临时UNDO段(Temporary Undo Segments)新特性.这个新特性把临时表产生的UNDO ...

最新文章

  1. 数据结构与算法:04 C#面向对象设计 II
  2. 学习笔记之三(数组中的一些方法)
  3. 模拟信号可以传输声音和图像,那么文字呢--信息论系列
  4. 乾颐堂安德HCIE课程3-OSPF的精华1、2类LSA,区域间的3类LSA和过滤策略
  5. CVPR 2019 | 小样本域适应的目标检测
  6. Oracle入门(十四.8)之迭代控制:基本循环Loop
  7. npu算力如何计算_CPU、GPU、NPU、FPGA等芯片架构特点分析
  8. 让你不差钱的9款开源网管工具
  9. 服务器mdl文件转换,Simulink Project 中 MDL 到 SLX 模型文件格式的转换
  10. 各种电子面单-Api接口(顺丰、快递鸟、菜鸟)
  11. Vulnhub靶机 it is october
  12. keras 中的verbose详解
  13. 含泪向小米贱卖处理器? 联发科:断章取义
  14. 匹配输入华为:编程实现联想输入法 输入联想功能是非常实用的一个功能,请编程实现类似功能...
  15. :要求查询出每一个雇员的编号,姓名,工资,领导的姓名,部门名称及位置,工资所在公司的工资等级
  16. 图形验证码和短信验证码
  17. Python爬取动态网页实例讲解
  18. pytdx 获取板块指数_通达信如何查看行业板块和概念板块的指数和K线图
  19. springboot学习(六十七) springboot项目通过gradle-docker-plugin插件构建为doker镜像并推送至镜像私服
  20. 硬件bypass原理介绍

热门文章

  1. 实现JPA的懒加载和无外键
  2. java string是final_关于java:String和Final
  3. redis实现高并发下的抢购/秒杀功能
  4. 使用gatling做压力测试与负载测试
  5. 微信小程序开发04-打造自己的UI库
  6. 14.19 InnoDB and MySQL Replication InnoDB 和MySQL 复制:
  7. hdu 1520 树形dp入门
  8. 使用正则test方法遇到的问题
  9. JAVA和JVM运行原理揭秘
  10. jQuery 集合 搜索操作(父辈元素搜索、同辈元素搜索、子元素搜索)