hdu 3264 Open-air shopping malls 求兩圓相交

來源:互聯網
上載者:User

標籤:blog   2014   os   name   c   for   

對每個圓二分半徑尋找可行的最小半徑,然後取最小的一個半徑。

對於兩圓相交就只要求到兩個扇形,然後減去兩個全等三角形就行了。


#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>using namespace std;#define pi acos(-1.0)#define eps 1e-8#define maxn 50int n;struct point{    double x;    double y;    double r;}c[maxn];double dis(point a,point b){   return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double area(point a,double ra,point b,double rb){    double ans=0;    double d=dis(a,b);    double temp;    if(ra<rb)  swap(ra,rb);    if(d>=ra+rb)return 0;    if(d<=ra-rb)return pi*rb*rb;    double angle1=acos((ra*ra+d*d-rb*rb)/2.0/ra/d);    double angle2=acos((rb*rb+d*d-ra*ra)/2.0/rb/d);    ans-=d*ra*sin(angle1);    ans+=angle1*ra*ra+angle2*rb*rb;    return ans;}bool cover_half(point a,double ra,point b,double rb)  //a是有傘的圓,b是其他圓{    return area(a,ra,b,rb)>=0.5*rb*rb*pi;}bool isok(double r,int k){    for(int i=1;i<=n;i++)    {        if(!cover_half(c[k],r,c[i],c[i].r)) return false;    }    return true;}int main(){    int cas;    scanf("%d",&cas);    while(cas--)    {        scanf("%d",&n);        for(int i=1;i<=n;i++)        {            scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);        }        double ans=5000000;        for(int i=1;i<=n;i++){            double l=0.0,r=5000000,mid;            while(l+eps<=r)            {                mid=(l+r)/2;                if(isok(mid,i)) r=mid-eps;                else l=mid+eps;            }            ans=min(ans,mid);        }        printf("%.4lf\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.