HDU-3264 (计算几何+二分)
来源:互联网 发布:基础架构java 编辑:程序博客网 时间:2024/06/10 21:00
问题描述:
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
120 0 12 0 1Sample Output
2.0822
题目题意:题目给我们n个圆的位置坐标和半径,然后让我们求一个大圆(它的圆心和某个小圆的圆心重合)能够至少覆盖每个小圆面积的一半的半径.
题目分析:由于题目给的小圆个数只有20个,所以我们可以枚举每一个小圆的圆心,然后二分去找半径,二分的判断条件就是让大圆与每个小圆相交求相交面积是否大于小圆的一半。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const double epx=1e-8;const double inf=1e8;const double PI=acos(-1.0);int n;struct note{ double x,y,r;}point[25];double area(struct note a,struct note b)//求的是俩圆的相交的面积(模板){ double r1=a.r,r2=b.r; double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));if (d >= r1+r2)return 0;if (r1>r2) swap (r1,r2);if(r2-r1 >= d)return PI*r1*r1;double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);}bool check (struct note o){ for (int i=0;i<n;i++) { if (area(o,point[i])>=((point[i].r*point[i].r*PI)/2.0))//大于小圆的一半 continue; else return false; } return true;}int main(){ int t; scanf("%d",&t); while (t--) { scanf("%d",&n); for (int i=0;i<n;i++) scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].r); double ans=inf; for (int i=0;i<n;i++) {//遍历每个小圆圆心 struct note o=point[i]; double left,right,mid; left=0,right=inf; while (right-left>epx) { mid=(left+right)/2; o.r=mid;//半径 if (check(o)) right=mid; else left=mid; } ans=min(ans,left); } printf("%.4f\n",ans); } return 0;}
- HDU-3264 (计算几何+二分)
- HDU 4033 二分+计算几何
- HDU/HDOJ 3264 计算几何+二分 2009 宁波区域赛
- 【二分+计算几何】hdu 4033 Regular Polygon
- 计算几何 [二分答案]
- hdu 3264 Open-air shopping malls 计算几何 相交圆的面积 二分
- HDU 3264 Open-air shopping malls(计算几何 && 二分优化)
- HDU 3264 Open-air shopping malls [相交圆面积+二分查找]【计算几何】
- HDU 4766 Network(计算几何 二分+三分)
- HDU 3156 Repair Depots DLX 计算几何 二分 暴力
- poj2398+poj2318(计算几何+二分)
- POJ 2318 计算几何+二分
- poj2318 toy 计算几何+二分
- hdoj4643GSM【计算几何+二分思想】
- poj2857Expanding Rods【二分+计算几何】
- 计算几何-二分求幂
- HDU4643 GSM 计算几何-二分
- hdu 3952 计算几何
- java并发编程之四
- [leetcode]233. Number of Digit One
- 迷宫最短路径 深度优先搜索—C—python
- 数的统计
- 现代OpenGL中,如何使用不同图元类型画一个正方形?
- HDU-3264 (计算几何+二分)
- 【web前端】仅使用JS做简单的选择题测评系统
- Linux下安装Tomcat服务器和部署Web应用
- Housewife Wind(译)
- OpenCV2编程手册笔记之 2.3指针遍历图像
- MOSFET实现not门电路
- 153. Find Minimum in Rotated Sorted Array
- redis安装及注意事项
- javaweb 小错误导致的大问题:001