Segments

http://poj.org/problem?id=3304

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 18066   Accepted: 5680

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 (x1y1) and (x2y2) 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! 枚举每两个线段的端点,判断这些端点形成的直线是否与线段都有交点
还有,题目说如果两个点的距离小于1e-8就看成一个点,所以要考虑重点
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std; struct Point{
double x,y;
}; struct Line{
Point s,e;
}line[]; double Cross(double x0,double y0,double x1,double y1,double x2,double y2){
return (x1-x0)*(y2-y0)-(y1-y0)*(x2-x0);
} double distance(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} bool Check(double x1,double y1,double x2,double y2,int n){
if(distance(x1,y1,x2,y2)<0.00000001) return ;
for(int i=;i<=n;i++){
if(Cross(x1,y1,x2,y2,line[i].s.x,line[i].s.y)*Cross(x1,y1,x2,y2,line[i].e.x,line[i].e.y)>0.00000001){
return ;
}
}
return ;
} bool ac(int n){
Line tmp;
int co=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
tmp.s=line[i].s;
tmp.e=line[j].s;
if(Check(tmp.s.x,tmp.s.y,tmp.e.x,tmp.e.y,n)){
co=;
}
tmp.s=line[i].s;
tmp.e=line[j].e;
if(Check(tmp.s.x,tmp.s.y,tmp.e.x,tmp.e.y,n)){
co=;
}
tmp.s=line[i].e;
tmp.e=line[j].s;
if(Check(tmp.s.x,tmp.s.y,tmp.e.x,tmp.e.y,n)){
co=;
}
tmp.s=line[i].e;
tmp.e=line[j].e;
if(Check(tmp.s.x,tmp.s.y,tmp.e.x,tmp.e.y,n)){
co=;
}
} }
if(co)
return true;
return false;
} int main(){ int T;
cin>>T;
while(T--){
int n;
cin>>n;
Point s,e;
for(int i=;i<=n;i++){
cin>>s.x>>s.y>>e.x>>e.y;
line[i].s=s;
line[i].e=e;
}
if(ac(n)){
puts("Yes!");
}
else{
puts("No!");
}
} }

Segments(叉积)的更多相关文章

  1. POJ 3304 Segments 叉积

    题意: 找出一条直线,让给出的n条线段在这条直线的投影至少有一个重合的点 转化一下,以重合的点作垂线,那么这条直线一定经过那n条线段.现在就是求找到一条直线,让这条直线经过所有线段 分析: 假设存在这 ...

  2. POJ 3304 Segments【叉积】

    题意:有n条线段,问有没有一条直线使得所有线段在这条直线上的投影至少有一个共同点. 思路:逆向思维,很明显这个问题可以转化为是否有一条直线穿过所有线段,若有,问题要求的直线与该直线垂直,并且公共点为垂 ...

  3. poj 3304 Segments

    Segments 题意:给你100以内的n条线段,问你是否存在一条直线,使得题给的线段在这条直线上的“投影” 相交于一点: 思路: 1.先要将线段投影相交于一点转变为存在一条直线与所有的线段相交: 很 ...

  4. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

  5. (叉积,线段判交)HDU1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  6. POJ 3304 Segments(线的相交判断)

    Description Given n segments in the two dimensional space, write a program, which determines if ther ...

  7. POJ 3304 Segments 判断直线和线段相交

    POJ 3304  Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...

  8. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  9. Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor

    结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...

随机推荐

  1. Linux Shell脚本编程--Linux特殊符号大全

    Linux Shell脚本编程--Linux特殊符号大全 linux_shell 特殊符号的介绍 2011

  2. 绕过限制,在PC上调试微信手机页面

    场景 假设一个手机页面,开发者对其做了限制,导致只能在微信客户端中打开.而众所周知手机上非常不利于调试页面,所以需要能在电脑上打开并进行调试.这里针对常见的三种页面做一下分析,一一绕过其限制,(当然不 ...

  3. centos 7.5 安装mysql

    1.Mysql: 在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1.下载并安装MySQL官 ...

  4. 用cmd导入oracle的.dmp文件和修改oracle管理员密码

    1,首先创建用户 语法[创建用户]: create user 用户名 identified by 口令[即密码]: 例子:create user zhengxin identified by zhen ...

  5. python logging模块使用教程

    简单使用 #!/usr/local/bin/python # -*- coding:utf-8 -*- import logging logging.debug('debug message') lo ...

  6. 一些你需要知道的Python代码技巧

    被人工智能捧红的 Python 已是一种发展完善且非常多样化的语言,其中肯定有一些你尚未发现的功能.本文或许能够让你学到一些新技巧.   Python 是世界上最流行.热门的编程语言之一,原因很多,比 ...

  7. tomcat原理解析(一):一个简单的实现

    tomcat原理解析(一):一个简单的实现 https://blog.csdn.net/qiangcai/article/details/60583330 2017年03月07日 09:54:27 逆 ...

  8. 17.scrapy框架简例使用

    目标:创建scrapy项目 创建一个spider来抓取站点和处理数据 通过命令行将抓取内容导出 1.创建项目 scrapy startproject tutorial 2.创建spider cd tu ...

  9. 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效。

    # 69.0 之后的版本 ## 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效.关闭Enable Ephemeral Flash Permissions , ...

  10. sitemap

    sitemap对于网站就像是字典的索引目录,而这个目录的读者则是搜索引擎的爬虫.网站有了sitemap,有助于搜索引擎“了解”网站,这样会有助于站点的内容被收录. sitemap是一个由google主 ...