poj 3304 计算几何

时间:2023-03-09 16:01:53
poj 3304 计算几何
 大意: 是否存在一条直线,使所有线段在直线上的投影至少交与一点

  思路: 转换为是否存在一条直线与所有的线段相交,做这条直线的垂线,那么垂线即为所求

 **/
#include <iostream>
#include <cmath>
using namespace std;
int n;
const double eps = 1e-;
struct point{
double x,y;
}; struct line{
point a,b;
};
line l[];
double dis(point o,point p){
return sqrt((o.x-p.x)*(o.x-p.x)+(o.y-p.y)*(o.y-p.y));
} double cross(point o,point p,point q){
return (p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x);
}
int judge(point t1,point t2){
if(dis(t1,t2)<eps)
return ;
for(int i=;i<n;i++)
if(cross(t1,t2,l[i].a)*cross(t1,t2,l[i].b)>eps)
return ;
return ;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=;i<n;i++)
cin>>l[i].a.x>>l[i].a.y>>l[i].b.x>>l[i].b.y;
int flag =;
if(n==)
flag =;
for(int i=;!flag&&i<n;i++){
for(int j=;!flag&&j<n;j++){
if(judge(l[i].a,l[j].a)||judge(l[i].a,l[j].b)||judge(l[i].b,l[j].a)||judge(l[i].b,l[j].b))
flag =;
}
}
if(flag)
cout<<"Yes!"<<endl;
else{
cout<<"No!"<<endl;
}
}
}