http://poj.org/problem?id=3304
判斷所有線段段點是否能出現一個直線經過所有線段
#include<iostream>
#include<math.h>
#include<cstdio>
const double eps = 1e-8;
const int maxn = 1005;
using namespace std;
struct node{
double x;
double y;
}sta[maxn],en[maxn];
int n;
double dis(const node p1,const node p2){
return sqrt(fabs((p1.x-p2.x))*fabs((p1.x-p2.x))+fabs((p1.y-p2.y))*fabs((p1.y-p2.y)));
}
double mul(node p1,node p2,node p3){
return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}
int judge(const node p1,const node p2){
if(dis(p1,p2)<=eps) return 0;
for(int i=0;i<n;i++){
if(mul(p1,p2,sta[i])*mul(p1,p2,en[i])>eps){
return 0;
}
}
return 1;
}
int solve(){
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(judge(sta[i],sta[j])||judge(sta[i],en[j])||judge(en[i],sta[j])||judge(en[i],en[j])){
return 1;
}
}
}
return 0;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;i++){
cin>>sta[i].x>>sta[i].y>>en[i].x>>en[i].y;
}
if(n==1){
cout<<"Yes!"<<endl;
continue;
}
if(solve()) cout<<"Yes!"<<endl;
else cout<<"No!"<<endl;
}
return 0;
}