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/ ...
随机推荐
- 【JZOJ4711】【NOIP2016提高A组模拟8.17】Binary
题目描述 输入 输出 样例输入 6 6 8 9 1 13 9 3 1 4 5 2 6 9 1 3 7 2 7 7 1 6 1 2 11 13 样例输出 45 19 21 数据范围 解法 40%暴力即可 ...
- JavaScript--预解析在IE存在的问题
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 介绍(javascript调试)
Chrome developer tool Chrome浏览器得益于其优秀的V8解释器,javascript执行速度和内存占有率表现非常优秀.对于html+css+javascript前台技术的学习或 ...
- 深入浅出Cocoa之消息【转】
在入门级别的ObjC 教程中,我们常对从C++或Java 或其他面向对象语言转过来的程序员说,ObjC 中的方法调用(ObjC中的术语为消息)跟其他语言中的方法调用差不多,只是形式有些不同而已. 譬如 ...
- 【Leetcode Top-K问题 BFPRT】第三大的数(414)
题目 给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是O(n). 示例 1: 输入: [3, 2, 1] 输出: 1 解释: 第三大的数是 1. 示 ...
- viewpager实现进入程序之前的欢迎界面效果
用viewpager实现该效果大致需要5步 1,用support.v4包下的ViewPager.xml布局如下: <android.support.v4.view.ViewPager andro ...
- 【JZOJ4934】【NOIP2017GDKOI模拟1.12】a
helpless fucking 结论:如果一个数可以被对于a序列中每个数的最大公约数整除,那么它就是好的. Bitch Man 感性证明: 贪心地想,对于a序列中的任意两个数,它们的最大公约数可由这 ...
- 小爬爬5:scrapy介绍2
1.scrapy:爬虫框架 -框架:集成了很多功能且具有很强通用性的一个项目模板 -如何学习框架:(重点:知道有哪些模块,会用就行) -学习框架的功能模板的具体使用. 功能:(1)异步爬取(自带buf ...
- linux下的OpenCV安装&学习笔记
http://www.linuxdiyf.com/viewarticle.php?id=20731 (本想在fedora下安装编译的,但目前opencv官网.sourceforge等网站都无法访问下载 ...
- JDBC操作数据库实例
jdbc操作数据库实例 1.jdbc创建数据库 1.1 前提条件 1.拥有创建和删除表的权限 2.数据库已经启动,且可用 1.2 jdbc创建数据库表的步骤: 导包:导入需要进行数据库编程的 JDBC ...