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 ...
随机推荐
- eclipse怎么导入maven项目 eclipse导入maven项目详细教程
转自:http://www.pc6.com/infoview/Article_114542.html Eclipse怎么导入maven项目一直是困扰着大量程序猿和刚上手小白们的问题,使用eclipse ...
- 前端-CSS-9-文本和字体-背景颜色
字体属性 div{ width: 300px; height: 100px; /*background-color: red;*/ border: 1px solid red; /*设置字体大小 px ...
- centos7 jenkins 安装
前提: 安装了 jdk ,我的是jdk8 第一步: https://jenkins.io/download/ 下载 可以下载 rpm文件, 标红处, 也可以下载war包(Generic Java pa ...
- Mysql 知识(1)
1. 请简洁地描述下MySQL中InnoDB支持的四种事务隔离级别名称,以及逐级之间的区别? 答: SQL标准定义的四个隔离级别为:read uncommited,read committed,rep ...
- MYsql系统函数和联合查询
函数是SQL里的关键字,用于对字段里的数据进行操作.函数是一个命令,通常与字段名称或者是表达式联合使用,处理输入的数据并产生结果 常用函数 控制函数 字符串函数 数学函数 日期时间函数 汇总函数 CA ...
- JAVA中会存在内存泄露吗
所谓内存泄露就是指一个不再被程序使用的对象或变量一直被占据在内存中.java中有垃圾回收机制,它可以保证一对象不再被引用的时候,即对象编程了孤儿的时候,对象将自动被垃圾回收器从内存中清除掉.由于Jav ...
- SPARK数据类型
转自: http://www.cnblogs.com/tuitui1989/p/5331113.html 一.本地向量 有如下几个类: Vector(基类),DenseVector,SparseVec ...
- Linux就业技术指导(二):简历项目经验示例
一,期中项目经验示例 1.1 新服务器上线搭建系统环境 1,根据现有结构部署工具(PXE+kickstart) 2,结合应用系统需求定制部署模版 3,制作系统优化等一键执行脚本 4,自动化部署实施 5 ...
- Java工具类_随机生成任意长度的字符串【密码、验证码】
import java.util.Random; public class PasswordCreate { /** * 获得密码 * @param len 密码长度 * @return */ pub ...
- windows server 2008 远程桌面连接数修改--无限连接
1.开启远程桌面 我的电脑 | 属性 | 远程设置 | 远程 | 进允许运行使用网络级别身份验证的远程桌面的计算机连接(更安全)(N)