HDU 3264 Open-air shopping malls(兩圓相交公用部分面積 二分答案)

來源:互聯網
上載者:User
Open-air shopping malls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1427    Accepted Submission(s): 500


Problem DescriptionThe city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people crowded into these shopping malls and enjoy the vary-different shopping.

Unfortunately, the climate has changed little by little and now rainy days seriously affected the operation of open-air shopping malls—it’s obvious that nobody will have a good mood when shopping in the rain. In order to change this situation, the manager of
these open-air shopping malls would like to build a giant umbrella to solve this problem. 

These shopping malls can be considered as different circles. It is guaranteed that these circles will not intersect with each other and no circles will be contained in another one. The giant umbrella is also a circle. Due to some technical reasons, the center
of the umbrella must coincide with the center of a shopping mall. Furthermore, a fine survey shows that for any mall, covering half of its area is enough for people to seek shelter from the rain, so the task is to decide the minimum radius of the giant umbrella
so that for every shopping mall, the umbrella can cover at least half area of the mall. 


InputThe input consists of multiple test cases. 
The first line of the input contains one integer T (1<=T<=10), which is the number of test cases.
For each test case, there is one integer N (1<=N<=20) in the first line, representing the number of shopping malls.
The following N lines each contain three integers X,Y,R, representing that the mall has a shape of a circle with radius R and its center is positioned at (X,Y). X and Y are in the range of [-10000,10000] and R is a positive integer less than 2000. 


OutputFor each test case, output one line contains a real number rounded to 4 decimal places, representing the minimum radius of the giant umbrella that meets the demands. 


Sample Input

120 0 12 0 1
 


Sample Output

2.0822
 


Source2009 Asia Ningbo Regional Contest Hosted by NIT 


Recommendlcy 這個題目比較有意思這個題目兩個圓相交公式是參考這篇部落格:http://blog.sina.com.cn/s/blog_850498e20100w6fq.html對於這個題目個人感覺比較有意思,也比較好想,首先看這個題目的資料量比較小,肯定枚舉能搞定然後想求出答案,貌似不好直接求出答案,這時候想到二分枚舉答案,不過精度要控好
這個題目不要想當然的認為離當前圓心最遠的點就是答案的出現點,只要在那個圓上枚舉就可以了,這個想法是錯誤的,假設這個圓半徑很小呢,那麼枚舉出來的結果可能就是錯誤的!

#include <iostream>#include <string.h>#include <stdio.h>#include <cmath>using namespace std;#define eps 1e-8#define pi acos(-1.0)struct point{ double x; double y; double r; double area;}po[200];int n;double global_ans;double map[50][50];double area(point a,double r1,point b,double r2){ double d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));//圓心距 if(r1>r2) { double temp=r1; r1=r2; r2=temp; }//r1取小 if(r1+r2<=d) return 0;//相離 else if(r2-r1>=d) return pi*r1*r1;//內含 else { double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d)); double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d)); return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1)); }//相交}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 find_ans(int num,double left,double right){    double temp,mid;    if(right > global_ans)    right=global_ans;    int i;    while(right - left > eps)    {        mid=(right+left)/2;        for(i=0;i<n;i++)        {            temp=area(po[num],mid,po[i],po[i].r);            if(temp < po[i].area/2)            { left=mid;break;}        }        if(i==n)        right=mid;    }  if(global_ans > (left+right)/2)  global_ans=(left+right)/2;  return 0;}int main(){    int t;    int i,j;    scanf("%d",&t);    double MAX;    while(t--)    {        scanf("%d",&n);        MAX=-1;        for(i=0;i<n;i++)        {            scanf("%lf%lf%lf",&po[i].x,&po[i].y,&po[i].r);            po[i].area=pi*po[i].r*po[i].r;        }        if(n==1)        {           printf("%.4lf\n",po[0].r/sqrt(2.0)); //////////////////////////////////////           continue;        }        for(i=0;i<n;i++)        for(j=i;j<n;j++)         map[i][j]=map[j][i]=dis(po[i],po[j]);         global_ans=1e8;        for(i=0;i<n;i++)         find_ans(i,0,1e6);        printf("%.4lf\n",global_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.