hdu 3304(直线与线段相交)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12042 | Accepted: 3808 |
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!
可以理解成如果直线合法,然后旋转的话总是会和某两条直线的端点相交,枚举端点。找到一条合法的。
这题用规范相交就过了。
///判断直线与线段相交
///做法:枚举每两个端点,要是存在一条直线经过这两个端点并且和所有线段相交就OK,但是不能为重合点.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps = 1e-;
const int N = ;
struct Point
{
double x,y;
};
struct Line{
Point a,b;
}line[N];
int n; double cross(Point a,Point b,Point c){
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double dis(Point a,Point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool isCross(Point a,Point b,Point c,Point d){///这个函数判断直线和线段是否相交,直线是无线延长的,所以一个点在这一边一个点在那一边就OK
if(cross(a,b,c)*cross(a,b,d)>) return true;
return false;
}
bool check(Point a,Point b){
if(sqrt(dis(a,b))<eps) return false;//这里记得讨论
for(int i=;i<n;i++){
if(isCross(a,b,line[i].a,line[i].b)){
return false;
}
}
return true;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf%lf%lf",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y);
}
if(n==||n==) {
printf("Yes!\n");
continue;
}
bool flag=false;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(check(line[i].a,line[j].a)||check(line[i].b,line[j].b)||check(line[i].a,line[j].b)||check(line[i].b,line[j].a)){
flag = true;
break;
}
}
if(flag) break;
}
if(flag) printf("Yes!\n");
else printf("No!\n");
}
return ;
}
hdu 3304(直线与线段相交)的更多相关文章
- poj 3304(直线与线段相交)
传送门:Segments 题意:线段在一个直线上的摄影相交 求求是否存在一条直线,使所有线段到这条直线的投影至少有一个交点 分析:可以在共同投影处作原直线的垂线,则该垂线与所有线段都相交<==& ...
- 判断直线与线段相交 POJ 3304 Segments
题意:在二维平面中,给定一些线段,然后判断在某直线上的投影是否有公共点. 转化,既然是投影,那么就是求是否存在一条直线L和所有的线段都相交. 证明: 下面给出具体的分析:先考虑一个特殊的情况,即n=1 ...
- POJ 1039 Pipe(直线和线段相交判断,求交点)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8280 Accepted: 2483 Description ...
- POJ 1039 直线和线段相交
题意: 题意很好理解,从左边射过来的光线,最远能经过管道到右边多少距离. 分析: 光线一定经过一个上端点和一个下端点,这一点很容易想到.然后枚举上下端点即可 #include <iostream ...
- POJ 3304 Segments(计算几何:直线与线段相交)
POJ 3304 Segments 大意:给你一些线段,找出一条直线可以穿过全部的线段,相交包含端点. 思路:遍历全部的端点,取两个点形成直线,推断直线是否与全部线段相交,假设存在这种直线,输出Yes ...
- POJ 3304 Segments 判断直线和线段相交
POJ 3304 Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...
- POJ 3304 Segments (判断直线与线段相交)
题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- Segments POJ 3304 直线与线段是否相交
题目大意:给出n条线段,问是否存在一条直线,使得n条线段在直线上的投影有至少一个公共点. 题目思路:如果假设成立,那么作该直线的垂线l,该垂线l与所有线段相交,且交点可为线段中的某两个交点 证明:若有 ...
随机推荐
- 【iOS开发】iOS CGRectGetMaxX/Y 使用
在iOS的界面布局中我们可以使用CGRectGetMaxX 这个方法来方便的获取当前控件的x坐标值+宽度的数值,这样便可以方便布局. 同理CGRectGetMaxY是获取y坐标值+控件高度的值,当然这 ...
- Name node is in safe mode.
刚才启动hadoop,然后执行rm -r命令,出现这个问题,标记为红色的部分意思是namenode是安全节点, [master@hadoop file]$ hadoop fs -rm -r /inp ...
- php laravel 框架搭建与运行
目录 安装 composer 安装 laravel 运行 php hello world 一.安装 composer (mac) 下载 composer.phar 下载地址:https://getco ...
- Redis学习笔记之基础篇
Redis是一款开源的日志型key-value数据库,目前主要用作缓存服务器使用. Redis官方并没有提供windows版本的服务器,不过微软官方开发了基于Windows的Redis服务器Micro ...
- Windows 64下elasticsearch-1.7.1集群 安装、启动、停止
elasticsearch-1.7.1 (es Windows 64) 安装.启动.停止的详细记录 https://blog.csdn.net/qq_27093465/article/details/ ...
- Div+Css中transparent制作奥运五环
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [洛谷P4838]P哥破解密码
题目大意:求长度为$n$的$01$串中,没有连续至少$3$个$1$的串的个数 题解:令$a_1$为结尾一个$1$的串个数,$a_2$为结尾两个$1$的串的个数,$b$为结尾是$0$的串的个数.$a_1 ...
- MySQL之数据库及表的修改和删除
本文章来自实验楼的操作过程和其中相应地解释.(博客园不知道怎么回事,上传图片总是失败.) 一.对数据库修改 1)删除数据库的命令为:DROP DATABASE 数据名; 二.对表的修改 1)重命名一张 ...
- 遇到问题---java---myeclipse发布项目打包项目resource资源有缓存---log4j.properties新配置不起作用
在使用myeclipse过程中遇到一个很奇怪的问题,无论是在myeclipse中deploy发布到tomcat或者打包打成war后在tomcat中运行解压,resource都有缓存的感觉. 比较明显的 ...
- rest与restful
知乎上面摘抄的,感觉不错,分享下: https://www.zhihu.com/question/28557115 1. REST描述的是在网络中client和server的一种交互形式:RES ...