Segments
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8579   Accepted: 2608

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! 题目大意:问是否存在一条直线所有线段在它上面的投影至少有一个公共交点,等同与这条直线的垂线与所有线段都有交点。即求是否有一条与所有线段相交。两两枚举线段四个端点两两成四条直线,
若所有的线段的两个端点分别在直线的两边(只要不是在同一边就行,在直线上也可以),那么说明存在这么一条直线。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std; struct Point{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
}; struct Segment{
Point a,b;
}; typedef Point Vector;
Vector operator -(const Point &A,const Point &B){ return Vector(A.x-B.x,A.y-B.y);}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps=1e-; int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
} bool operator == (const Point &a,const Point &b){
return (dcmp(a.x-b.x)== && dcmp(a.y-b.y)==);
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量长度
//两向量的夹角
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}
double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积 vector<Segment> S; bool judge(Point a,Point b)
{
if(a == b) return false;//a,b属于同一个点,一个点不能确定一条直线
int i,n=S.size();
Vector v1=b-a,v2,v3;
for(i=;i<n;i++)
{
v2=S[i].a-a;
v3=S[i].b-a;
if(dcmp(Cross(v1,v2)*Cross(v1,v3)) > ) return false;
}
return true;
} bool solve()
{
int i,j,n=S.size();
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
if(judge(S[i].a,S[j].a) || judge(S[i].a,S[j].b) || judge(S[i].b,S[j].a) || judge(S[i].b,S[j].b))
return true;
}
return false;
}
int main()
{
int T,n,i;
Segment s;
scanf("%d",&T);
while(T--)
{
S.clear();
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%lf %lf %lf %lf",&s.a.x,&s.a.y,&s.b.x,&s.b.y);
S.push_back(s);
}
if(n==) printf("Yes!\n");
else if(solve()) printf("Yes!\n");
else printf("No!\n");
}
return ;
}

最新文章

  1. JDBC删除表数据
  2. 我爱记单词(iWords)之NABC by张恿
  3. Python学习笔记(二)基本语法
  4. SQL迁移到ORACLE实例
  5. 编程中i++与++i的区别
  6. 安装ubuntu时将boot目录单独挂载的意义
  7. JS正则表达式简单总结
  8. bzoj 3283: 运算器 扩展Baby Step Giant Step &amp;&amp; 快速阶乘
  9. c# 调用 友盟api
  10. javascript模式——Facade
  11. [ios2]Emoji表情符号兼容方案 【转】
  12. hadoop以及相关组件介绍以及个人理解
  13. botzone Tetris2
  14. 解决eclipse maven工程中src/main/resources目录下创建的文件夹所显示样式不是文件夹,而是&quot;包&quot;图标样式的问题
  15. C#微信公众号——自定义菜单
  16. 3种vue路由传参的基本模式
  17. 虚拟机之openVZ简单基础
  18. blkblock工具1
  19. MACHINE_START-内核板级初始化实现机制(linux3.1.0)
  20. DHCP服务(dhcpd)

热门文章

  1. A. Pride (emmmm练习特判的好题)
  2. python基础面试题整理---从零开始 每天十题(02)
  3. C++ static关键字
  4. https 调用验证失败 peer not authenticated
  5. shell脚本,按行读取文件的几种方法。
  6. 低性能3张图片轮播React组件
  7. Fortran学习记录3(选择语句)
  8. [CODEVS] 3955 最长严格上升子序列(加强版)
  9. Web框架之Django_06 模型层了解(F查询、Q查询、事务、update和save、only和defer、choice属性、bulk_create)
  10. windows中Python多版本与jupyter notebook中使用虚拟环境