poj3304

maksyuki 发表于 oj 分类,标签:
0

Segments

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!

Source

Amirkabir University of Technology Local Contest 2006

 

题目类型:直线与线段相交

算法分析:首先若存在一条直线使得所有线段在该直线上的投影都至少有一个交点的话,从这个相交的区域向各个线段做垂线与各线段都相交,所以本题其实求解的是是否存在一个与所有线段都相交的直线。由于直线与一组线段相交的话,可以通过平移和旋转在保证直线仍与所有线段相交时恰好通过所有线段的某两个端点,即若存在一条直线与所有线段相交,则该直线必定经过这些线段的某两个端点,所以枚举线段的端点构造直线并判断即可,注意若枚举到相同点时要跳过