hdu 3264 Open-air shopping malls(圆相交面积+二分)
Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2458 Accepted Submission(s):
906
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.
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.
number rounded to 4 decimal places, representing the minimum radius of the giant
umbrella that meets the demands.
其中用到了圆相交面积,可以参考这题: http://www.cnblogs.com/pshw/p/5711251.html
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define N 25 const double pi = acos(-1.0);
const double EPS = 1e-;
int n; double max(double a,double b)
{
return a>b?a:b;
} double min(double a,double b)
{
return a<b?a:b;
} struct Round
{
double x,y;
double r;
} rr[N],s; double dis(Round a, Round b) ///两点之间的长度
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double solve(Round a, Round b) ///求两圆相交的面积
{
double d = dis(a, b);
if(d >= a.r + b.r)
return ;
else if(d <= fabs(a.r-b.r))
{
double r = a.r < b.r?a.r : b.r;
return pi * r * r;
}
double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / 2.0 / a.r / d);
double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / 2.0 / b.r / d);
double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1);
return ret;
} bool check(Round s)
{
for(int i=; i<n; i++) ///大圆是否覆盖每个圆的一半面积
{
if(solve(s, rr[i]) * < pi * rr[i].r * rr[i].r)
return false; ///不满足直接返回
}
return true;
} double bin(double l, double r, Round s) ///二分,找出最小圆的半径
{
double mid;
while(fabs(l - r) >= EPS) ///精度划分
{
mid = (l + r) / ;
s.r = mid;
if(check(s)) ///满足返回的说明半径长度足够,有可能可以更短
r=mid;
else ///不满足返回的说明半径长度不够,需要更长
l=mid+EPS;
}
return mid;
} int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=; i<n; i++)
scanf("%lf%lf%lf",&rr[i].x,&rr[i].y,&rr[i].r);
double ans = 1e10;
for(i=; i<n; i++)
{
s.x = rr[i].x;
s.y = rr[i].y;
double right = ;
for(j=; j<n; j++)
{
right = max(right, dis(s, rr[j]) + rr[j].r);
///以当前点为圆心,找出可以覆盖所有的圆面积的最长半径
}
ans = min(ans, bin(, right, s)); ///二分搜索,记录最小的圆的半径
}
printf("%.4f\n", ans);
}
return ;
}
hdu 3264 Open-air shopping malls(圆相交面积+二分)的更多相关文章
- hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- [hdu 3264] Open-air shopping malls(二分+两圆相交面积)
题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右 ...
- HDU 3467 (求五个圆相交面积) Song of the Siren
还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位 ...
- hdu 5120(2014北京—求圆相交)
题意:求环的相交面积 思路: 通过画图可知,面积= 大圆相交面积 - 大小圆相交面积*2 + 小小圆相交面积 再通过圆相交模板计算即可 #include <iostream> #incl ...
- 【HDU 5858】Hard problem(圆部分面积)
边长是L的正方形,然后两个半径为L的圆弧和中间直径为L的圆相交.求阴影部分面积. 以中间圆心为原点,对角线为xy轴建立直角坐标系. 然后可以联立方程解出交点. 交点是$(\frac{\sqrt{7} ...
- poj2546Circular Area(两圆相交面积)
链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...
- hdu 3264(枚举+二分+圆的公共面积)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- java利用JXL导出/生成 EXCEL【my】
一.创建一个excel文件 package test;// 生成Excel的类 import java.io.File; import jxl.Workbook;import jxl.write.La ...
- The content of element type must match解决方法
当我在mybatis的核心配置文件SqlMapConfig.xml中配置别名的时候,老是提示错误. 把鼠标移到上去就可以看到详细的内容 如下图所示: 问题原因: 通过错误的提示信息,原来这个xml文件 ...
- mybatis添加数据返回主键
程序结构图: 表结构: 创表sql: Create Table CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `us ...
- NLTK的探索
import nltk import random from nltk.corpus import movie_reviews documents = [(list(movie_reviews.wor ...
- Listview的条目item内的点击响应事件
还是这张图 这里的历史列表就是一个ListView,抛开该界面中ScrollView或者RecycleView与该ListView会有冲突,所谓的冲突,说白了就是父控件与子控件两者间的关系冲突,该冲突 ...
- Hdu 1045 二分匹配
题目链接 Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1251 统计难题(trie树入门)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- POJ1485 Sumdiv
Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22680 Accepted: 5660 Descripti ...
- (续)使用Django搭建一个完整的项目(Centos7+Nginx)
django-admin startproject web cd web 2.配置数据库(使用Mysql) vim web/settings.py #找到以下并按照实际情况修改 DATABASES = ...
- Wireshark抓包常见问题解析(转)
1. tcp out-of-order(tcp有问题) 解答: 1). 应该有很多原因.但是多半是网络拥塞,导致顺序包抵达时间不同,延时太长,或者包丢失,需要重新组合数据单元 因为他们可能是通过不同的 ...