几何入门
先贴着http://blog.csdn.net/wangjian8006
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; #define eps 1e-8 #define maxn 110 struct Line { double x1,y1,x2,y2; void input(double a,double b,double c,double d) { x1=a,y1=b,x2=c,y2=d; } }L[maxn]; int n; int sgn(double x) { return x<-eps?-1:x>eps?1:0; } double dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double cross(double x1,double y1, double x2,double y2,double x,double y) { return (x2-x1)*(y-y1)-(x-x1)*(y2-y1); } bool judge(double x1,double y1,double x2,double y2) { if(dis(x1,y1,x2,y2)<eps) return 0; for(int i=0;i<n;i++) if(cross(x1,y1,x2,y2,L[i].x1,L[i].y1)*cross(x1,y1,x2,y2,L[i].x2,L[i].y2)>eps) return 0; return 1; } int main() { int t; double a,b,c,d; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&a,&b,&c,&d); L[i].input(a,b,c,d); } if(n==1) { printf("Yes!\n"); continue; } int ans=0; for(int i=0;i<n&&!ans;i++) for(int j=i+1;j<n&&!ans;j++) if( judge(L[i].x1,L[i].y1,L[j].x1,L[j].y1) || judge(L[i].x1,L[i].y1,L[j].x2,L[j].y2) || judge(L[i].x2,L[i].y2,L[j].x1,L[j].y1) || judge(L[i].x2,L[i].y2,L[j].x2,L[j].y2)) ans=1; if(ans) printf("Yes!\n"); else printf("No!\n"); } return 0; }