POJ3304(计算几何基础-判断线段与直线相交)

该博客探讨了如何确定是否存在一条直线,使得给定的n条线段在其投影上至少有一个共同点。通过计算几何的方法,将问题转化为判断每条线段是否与特定直线相交。给出了样例输入和输出,并提供了解题思路,即枚举线段端点以检查相交情况。
摘要由CSDN通过智能技术生成

Segments
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 14774 Accepted: 4690
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条线段,问你存不存在一条直线,使得这n条线段在这条直线上的投影至少有一个公共点。

解题思路:问题可以转换为存不存在一条直线与n条线段都相交,那么我们要求的线段就与这条线段垂直,那么我们要找一条直线与这n条线段都相交,只需要枚举所有两条线段的端点(也要枚举一条线段自身的两个端点),然后判断这两个端点组成的直线与n条线段是否相交。

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值