叉积+暴力
注意变量前后要保持一致,以为这个问题wa了很多发
#include<iostream>
#include<cmath>
using namespace std;
#define maxn 105
#define precision 1e-10
int n;
struct Point{
double x;
double y;
};
Point Left[maxn],Right[maxn];
double det(double x1,double y1,double x2,double y2){
return x1*y2-x2*y1;
}
double cross(Point a,Point b,Point c){
return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
int check(Point a,Point b){
if(abs(a.x-b.x)<precision&&abs(a.y-b.y)<precision){
return 0;
}
for(int i=1;i<=n;i++){
if(cross(Left[i],a,b)*cross(Right[i],a,b)>precision){
return 0;
}
}
return 1;
}
int main(){
int T;
cin>>T;
while(T--){
cin>>n;
bool flag=0;
if(n<3){
flag=1;
}
for(int i=1;i<=n;i++){
cin>>Left[i].x>>Left[i].y;
cin>>Right[i].x>>Right[i].y;
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(flag){
break;
}
if(check(Left[i],Right[j])){
flag=1;
}else if(check(Left[i],Left[j])){
flag=1;
}else if(check(Right[i],Right[j])){
flag=1;
}else if(check(Right[i],Left[j])){
flag=1;
}
}
if(flag){
break;
}
}
if(flag){
cout<<"Yes!"<<endl;
}else{
cout<<"No!"<<endl;
}
}
return 0;
}