2018.07.04 POJ 3304 Segments(简单计算几何)
Segments
Time Limit: 1000MS Memory Limit: 65536K
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| < 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
Amirkabir University of Technology Local Contest 2006
又是一道基础的计算几何题,就是询问是否存在一条直线穿过给定的所有线段,由于n" role="presentation" style="position: relative;">nn很小,我们直接暴力枚举两个端点表示直线然后再O(n)" role="presentation" style="position: relative;">O(n)O(n)判断就行了(本蒟蒻因为有个return" role="presentation" style="position: relative;">returnreturn没有写调了40min" role="presentation" style="position: relative;">40min40min)。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define eps 1e-8
#define N 105
using namespace std;
struct pot{double x,y;}p[N<<1];
int n,t;
inline int sign(double x){return (x>eps)-(x<-eps);}
inline pot operator-(pot a,pot b){return pot{a.x-b.x,a.y-b.y};}
inline double cross(pot a,pot b){return a.x*b.y-a.y*b.x;}
inline bool ok(pot a,pot b,pot c,pot d){
if((cross(a-c,b-c)*cross(a-d,b-d))<=0.0000)return true;
return false;
}
inline bool pd(pot a,pot b){
for(int i=1;i<n;i+=2)if(ok(a,b,p[i],p[i+1])==0)return false;
return true;
}
inline bool check(){
for(int i=1;i<n;++i)
for(int j=i+1;j<=n;++j){
if(sign(p[i].x-p[j].x)==0&&sign(p[i].y-p[j].y)==0)continue;
if(pd(p[i],p[j]))return true;
}
return false;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
n<<=1;
for(int i=1;i<=n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
if(check())puts("Yes!");
else puts("No!");
}
return 0;
}
2018.07.04 POJ 3304 Segments(简单计算几何)的更多相关文章
- 2018.07.04 POJ 1265 Area(计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...
- POJ 3304 Segments(计算几何:直线与线段相交)
POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- 2018.07.04 POJ 1654 Area(简单计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- POJ 3304 Segments 判断直线和线段相交
POJ 3304 Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...
- POJ 3304 Segments(判断直线与线段是否相交)
题目传送门:POJ 3304 Segments Description Given n segments in the two dimensional space, write a program, ...
- POJ 3304 Segments (判断直线与线段相交)
题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...
随机推荐
- vue深入了解组件——插槽
一.插槽内容 Vue实现了一套内容分发的API,这套API基于当前的Web Components规范草案,将 <slot> 元素作为承载分发的内容的出口. 它允许你像这样合成组件: &l ...
- mongodb基础学习1-基本说明及安装
以前看过一些mongodb的视频,但只看到一半没有看完,也没有同步安装软件动手操作,正好最近没事,打算花点时间从头学习一遍,边学习边动手操作,学习的过程在此进行记录. 好了,下面说一下今天的学习内容. ...
- Why ExerciseAlone May Not Be the Key to Weight Loss
加强运动也许并不能减肥Why ExerciseAlone May Not Be the Key to Weight LossIf you give a mouse a running wheel, i ...
- scala-学习 2
列表操作 List() 或者是 Nil 空list scala> val a = List() a:List[Nothing] = List() print(a.length) a.length ...
- 重学Java
Java web 的课程告一段落了 现在我觉得我应该重新学习一下 Java基础 先分享下昨天学习递归后写的两个短短的代码 1.求5的阶乘 package test; public class fiv ...
- The requested resource (/) is not available解决办法
The requested resource (/) is not available HTTP Status 404(The requested resource is not available) ...
- Ansible 从MySQL数据库添加或删除用户
mysql_user - 从MySQL数据库添加或删除用户. 概要 要求(在执行模块的主机上) 选项 例子 笔记 状态 支持 概要 从MySQL数据库添加或删除用户. 要求(在执行模块的主机上) My ...
- SVN服务器的安装和使用
------------------siwuxie095 SVN 服务器的安装 1.SVN 服务器,选择 VisualS ...
- Java实现聚类算法k-means
2016-07 java简单实现聚类算法 但是有一个小问题,,,,我其实每次迭代之后(就是达不到我的收敛标准之前,聚类中心的误差达不到指定小的时候),虽然重新算了聚类中心,但是其实我的那些点并没有变, ...
- MySQL基本操作之命令行操作
MySQL基础操作 MySQL基础操作--命令行操作