博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3304——Segments(判断直线与多个线段相交)
阅读量:2344 次
发布时间:2019-05-10

本文共 1772 字,大约阅读时间需要 5 分钟。

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!

随便找两个线段,将两个端点以四种姿势连起来,判断是否与其他线段相交,暴力搞一搞就过了

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 5010#define Mod 10001using namespace std;struct point{ double x,y; point(){} point(double a,double b) { x=a; y=b; }};struct Line{ point s,e; Line(){} Line(point a,point b) { s=a; e=b; }};Line line[MAXN];double multy(point p0,point p1,point p2) //p0p1 x p0p2{ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool inter(Line l1,Line l2){ return multy(l2.s,l1.s,l1.e)*multy(l2.e,l1.s,l1.e)<=0;}double dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}bool check(Line a,int n){ if(dis(a.s,a.e)==0) return false; for(int i=0;i

转载地址:http://atcvb.baihongyu.com/

你可能感兴趣的文章
Python教程:Python数据类型之字典
查看>>
Python基础教程:python的数据类型
查看>>
Python学习教程:另辟蹊径,appium抓取app应用数据了解一下
查看>>
周董新歌《说好不哭》上线,20W评论,歌迷都说了些啥
查看>>
Python学习教程:用Python进行金融市场文本数据的情感计算
查看>>
Python爬虫:python获取各种街拍美图
查看>>
爬虫工程师是干什么的?你真的知道吗?
查看>>
写给那些想学Python的人,建议收藏后细看
查看>>
数据全裸时代,你的隐私有多容易获取?
查看>>
分析http代理报错问题
查看>>
Python编程学习笔记 - 列表的各种姿势
查看>>
Python学习教程:Python入门笔记整理
查看>>
天了噜,居然用Python查到了女神的姓名
查看>>
常用排序算法总结
查看>>
Java输入输出
查看>>
MSSQL数据库常见问题
查看>>
Java8 Lambda
查看>>
JAVA面试700问
查看>>
数据库DDL,DML,DCL,TCL
查看>>
各大数据库概述,比较
查看>>