hdu 4766 Network 長春網路賽 1008 計算幾何

來源:互聯網
上載者:User

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const int maxn=1e3+9;const double inf=1e11,epx=0.00001;int n;double rx,ry,d;double x[maxn],y[maxn];double cal(double x1,double y1,double x2,double y2){    double a=(x1-x2)*(x1-x2);    double b=(y1-y2)*(y1-y2);    return sqrt(a+b);}bool chk(double xx,double yy){    for(int i=1;i<=n;i++)    if(cal(xx,yy,x[i],y[i])>d+epx) return false;    return true;}int main(){//    freopen("in.txt","r",stdin);    while(scanf("%lf %lf",&rx,&ry)!=EOF)    {        scanf("%lf",&d);        scanf("%d",&n);        for(int i=1;i<=n;i++)        scanf("%lf %lf",&x[i],&y[i]);        bool flag=false;        double ans=inf;        if(chk(rx,ry))        {            ans=0;            flag=true;        }        for(int i=1;i<=n;i++)        {            double tmp=cal(x[i],y[i],rx,ry);            double xx=x[i]+(rx-x[i])*(d/tmp);            double yy=y[i]+(ry-y[i])*(d/tmp);            if(ans>cal(xx,yy,rx,ry))            if(chk(xx,yy))            {                ans=cal(xx,yy,rx,ry);                flag=true;            }        }        for(int i=1;i<=n;i++)        for(int j=i+1;j<=n;j++)        {            if(cal(x[i],y[i],x[j],y[j])>2*d+epx) continue;            if(fabs(x[i]-x[j])<epx&&fabs(y[i]-y[j])<epx) continue;            double x1=x[j]-x[i];            double y1=y[j]-y[i];            double xx=x[i]+x1/2,yy=y[i]+y1/2;            double tmp=cal(xx,yy,x[i],y[i]);            double txt=sqrt(d*d-tmp*tmp);            double ex,ey;            if(fabs(x1-0)>epx) ey=1,ex=-y1/x1;            else ex=1,ey=-x1/y1;            double tt=sqrt(ex*ex+ey*ey);            xx+=txt*ex/tt;            yy+=txt*ey/tt;            if(cal(xx,yy,rx,ry)<ans)            if(chk(xx,yy))            {                ans=cal(xx,yy,rx,ry);                flag=true;            }            xx-=txt*ex*2/tt;            yy-=txt*ey*2/tt;            if(cal(xx,yy,rx,ry)<ans)            if(chk(xx,yy))            {                ans=cal(xx,yy,rx,ry);                flag=true;            }        }        if(!flag) printf("X\n");        else printf("%.2lf\n",ans);    }    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.