poj 3304——Segments

來源:互聯網
上載者:User

幾何入門

先貼著http://blog.csdn.net/wangjian8006

#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;#define eps 1e-8#define maxn 110struct 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");elseprintf("No!\n");}return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.