博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3264 Constructing Roads(二分法)
阅读量:5311 次
发布时间:2019-06-14

本文共 3386 字,大约阅读时间需要 11 分钟。

Constructing Roads
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
 

Description

The 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.
 

Input

The 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.
 

Output

For 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

1 2 0 0 1 2 0 1
 

Sample Output

2.0822
 
 

题目的意思是:这个城市有许多的圆形商贸中心,这些圆形不相交,不包含。这天下雨了,需要一把巨大的伞来覆盖所有的商业中心,

要求这把伞以某一个商业圆的圆心作为它的圆心,并且至少覆盖商业圆面积的一半。求满足条件的最小的伞的半径

思路是:枚举把所有的商业中心当做圆心时,能取到的半径(这是因为题目的范围很小)

用二分法判断相交圆的面积是否等于商业圆面积的一半

 

# include
# include
double r2,d; //r2代表商贸圆的半径,d代表伞的圆心到商贸圆的圆心的距离,这两个变量用在求相交圆的面积上double ss; //商贸圆的面积的一半double pi=acos(-1.0);double left,right,mid; //二分法用到的变量struct node{ double x,y,r;}m[25]; double area(double r1){ //求相交圆的面积 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)); double s=(a1*r1*r1+a2*r2*r2-r1*d*sin(a1)); return s;}void f(){ //二分法求当伞刚好覆盖商贸圆面积的一半时的半径 double s; //表示相交圆的面积 s=area(mid); while(1){ if(fabs(s-ss)<=0.0000001) break; //double型变量不能直接用等于 if(ss-s>0.0000001) left = mid+0.0000001; if(s-ss>0.0000001) right = mid-0.0000001; mid=(left+right)/2.0; s=area(mid); }}int main(){ int T,n,i,j; double max,a,b,min; scanf("%d",&T); while(T--){ scanf("%d",&n); for(i=0;i
0.0000001) max=mid; } if(max-min<0.0000001) min=max; } printf("%.4lf\n",min); } return 0;}

 

转载于:https://www.cnblogs.com/acm-bingzi/archive/2013/03/13/2957037.html

你可能感兴趣的文章
判断是否为空然后赋值
查看>>
zabbix监控日志文件
查看>>
正则表达式
查看>>
pip install torch on windows, and the 'from torch._C import * ImportError: DLL load failed:' s...
查看>>
java基础(一):我对java的三个环境变量的简单理解和配置
查看>>
arcgis api 4.x for js 结合 Echarts4 实现散点图效果(附源码下载)
查看>>
YTU 2625: B 构造函数和析构函数
查看>>
apache自带压力测试工具ab的使用及解析
查看>>
C#使用Xamarin开发可移植移动应用(2.Xamarin.Forms布局,本篇很长,注意)附源码
查看>>
jenkins搭建
查看>>
C#中使用Split分隔字符串的技巧
查看>>
eclipse的调试方法的简单介绍
查看>>
加固linux
查看>>
IPSP问题
查看>>
10.17动手动脑
查看>>
WPF中Image显示本地图片
查看>>
Windows Phone 7你不知道的8件事
查看>>
实用拜占庭容错算法PBFT
查看>>
java的二叉树树一层层输出,Java构造二叉树、树形结构先序遍历、中序遍历、后序遍历...
查看>>
php仿阿里巴巴,php实现的仿阿里巴巴实现同类产品翻页
查看>>