HDU 3264 Open-air shopping malls (計算幾何-圓相交面積)

來源:互聯網
上載者:User

傳送門:http://acm.hdu.edu.cn/showproblem.php?pid=3264


給你n個圓,座標和半徑,然後要在這n個圓的圓心畫一個大圓,大圓與這n個圓相交的面積必須大於等於每個圓面積的一半,問你建在那個圓心半徑最小,為多少。

枚舉這n個圓,求每個圓的最小半徑,通過二分半徑來求,然後取這n個的最小值即可,注意點精度就OK了。


AC代碼:

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s)  scanf("%s",s)#define pi1(a)    printf("%d\n",a)#define pi2(a,b)  printf("%d %d\n",a,b)#define mset(a,b)   memset(a,b,sizeof(a))#define forb(i,a,b)   for(int i=a;i<b;i++)#define ford(i,a,b)   for(int i=a;i<=b;i++)typedef long long LL;const int N=33;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-8;int n;struct xkn{    double x,y,r;    double area;}p[22],h;double dis(xkn a,xkn b){    return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );}double fuck(xkn a,xkn b)  //求兩圓的相交面積函數。{    double d=dis(a,b);    if(d>=a.r+b.r) return 0;    double r=(a.r>b.r?b.r:a.r);    if( d<=fabs(a.r-b.r) ) return PI*r*r;    double A1=acos( (a.r*a.r+d*d-b.r*b.r)/2/a.r/d );    double A2=acos( (b.r*b.r+d*d-a.r*a.r)/2/b.r/d );    double res=A1*a.r*a.r + A2*b.r*b.r;    res-=sin(A1)*a.r*d;    return res;}bool xiaohao(xkn h){    for(int i=0;i<n;i++)    {        double jiao=fuck(p[i],h);        if(jiao<p[i].area/2)            return false;    }    return true;}int main(){//    freopen("input.txt","r",stdin);    int T;    si1(T);    while(T--)    {        si1(n);        for(int i=0;i<n;i++)        {            sd2(p[i].x,p[i].y);            sd1(p[i].r);            p[i].area=PI*p[i].r*p[i].r;        }        double Min=55555;        for(int i=0;i<n;i++)        {            double l=0,r=22222,m;            while((r-l)>eps)            {                m=(l+r)/2;                h=p[i]; h.r=m;                if(xiaohao(h))                    r=m;                else                    l=m;            }            if(Min>m)   Min=m;        }        printf("%.4f\n",Min);    }    return 0;}//92539932013-09-30 19:54:36Accepted32640MS320K2260 BG++XH_Reventon


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.