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 ...
随机推荐
- sendkeys
1)为了指定单一键盘字符,必须按字符本身的键.例如,为了表示字母 A,可以用 "A" 作为 string.为了表示多个字符,就必须在字符后面直接加上另一个字符.例如,要表示 A.B ...
- 4 并发编程-(进程)-守护进程&互斥锁
一.守护进程 主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了. 关于守护进程需要强调两点: 其一:守护进程会在主进程代码执行结束 ...
- Java synchronized(this)锁住的是什么
synchronized锁住的是括号里面的对象,而不是代码. 对于非static的synchronized方法,锁的就是对象本身,也就是this.
- box2d 易错
1.动态刚体与一个与静态刚体重叠的小的感应刚体在contactBegin时,有些时候无法侦测到 2.bodyA.GetContactList()应用非动态刚体,会找不到另一非动态刚体的接触,非动态刚体 ...
- 关于Integer的比较,今天又犯了一个低级错误,记录下
今天查看以前所写的代码,看到有一部分被人改了,代码如下: if (orgId != organizationUpdateReq.getOrgId()) { //orgId的类型为Integer,org ...
- Scala语言学习笔记(2)
表达式,值,变量,代码块,函数,方法 // 表达式 1 + 1 println(1 + 1) // 2 // 值(values)使用 val 关键字声明,带初值时类型可省略. val x = 1 + ...
- Javascript系列:总体理解
js是一个脚本客户端(浏览器)语言.和sql html类似.多练习. 没有排错的经验,弱类型语言,浏览器解释执行,出错也不会报错 预备 <!DOCTYPE html PUBLIC "- ...
- http://dl-ssl.google.com/android/eclipse/ 无法访问的解决办法
很明显,国内网络和谐掉了google这个服务器,可以强制指向下Host ,以下是添加内容: 74.125.237.1 dl-ssl.google.com 具体操作方式: 点击桌面左下角开始菜单中的搜索 ...
- 有名管道FIFO
管道和FIFO的特征之一是它们的数据是一个字节流.这是UNIX的原生I/O模型.进程往其中写入的是字节流,系统不对它作解释. FIFO不存数据,只是通过它找到内核文件. 一.建立有名管道 1.命令mk ...
- with as (转)
sql with as 用法(适用sqlserver,好像oracle也适用) Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效 ...