Open-air shopping malls

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

Problem 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
题意:平面上有一些圆,现在找一个圆的圆心为圆心做一个大圆出来,然后这个大圆至少要包含每个圆的1/2的面积,求这个大圆的最小半径。
题解:枚举每个点的圆心,二分求解。。WA了好久,竟然是我的圆公共面积的模板有问题,,幸好查出来了,,不然以后做模板的话有问题都不知道错哪里。。
内含的double 习惯性的打成了int
 
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double pi = atan(1.0)*;
const double eps = 1e-;
struct Circle{
double x,y,r;
}c[N];
typedef Circle Point;
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 Two_Circle_Area(Circle a,Circle b){
double d = dis(a,b);
if(a.r+b.r<d){ ///相离
return ;
}
if(fabs(a.r-b.r)>=d){ ///内含
double r = min(a.r,b.r);
return pi*r*r;
}
double angleA = acos((a.r*a.r+d*d-b.r*b.r)//a.r/d);
double angleB = acos((b.r*b.r+d*d-a.r*a.r)//b.r/d);
double area1 = a.r*a.r*angleA;
double area2 = b.r*b.r*angleB;
return area1+area2-a.r*d*sin(angleA);
}
int n;
double binary(double l,double r,Circle circle){
double mid;
while((r-l)>=eps){
mid = (l+r)/;
circle.r = mid;
bool flag = false;
for(int i=;i<n;i++){
double area = pi*c[i].r*c[i].r;
if(area/>Two_Circle_Area(circle,c[i])){
flag = true;
break;
}
}
if(flag) l =mid;
else r = mid;
}
return mid;
}
int main(){
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
}
Circle circle;
double mi = ;
for(int i=;i<n;i++){
circle.x = c[i].x;
circle.y = c[i].y;
double l=,r = ;
mi = min(mi,binary(l,r,circle));
}
printf("%.4lf\n",mi);
}
return ;
}

最新文章

  1. 郑捷《机器学习算法原理与编程实践》学习笔记(第四章 推荐系统原理)(二)kmeans
  2. MySQL数据库自带备份与恢复工具:MySQLdump.exe与mysql.exe
  3. iOS开发UI篇—Quartz2D使用(图片剪切)
  4. ZooKeeper快速搭建
  5. 6. Android框架和工具之 JSON解析
  6. linux远程执行命令
  7. MySQL的基本使用
  8. Apache HTTP Server mod_session_dbd 远程安全漏洞(CVE-2013-2249)
  9. Aspose.Words导出dt到word的问题
  10. 【ASP.NET Web API教程】5.1 HTTP消息处理器
  11. ssh无法远程登陆别的机器
  12. JavaScript分支语句if, else if, switch 案例详解
  13. 201521123023《Java程序设计》第7周学习总结
  14. 学习总结:工程管理与makefile
  15. 每日冲刺报告——Day4(Java-Team)
  16. 再见,segmentfault
  17. Vnpy二次开发应用所需图标
  18. MySQL 烂笔头 备份和还原
  19. Linux centOS Ubuntu --- 使用systemctl添加开机启动
  20. [daily][netctl] netctl有线网络连接使用802.1x进行验证上网

热门文章

  1. php jsonp单引号转义
  2. Python SimpleHTTPServer简单HTTP服务器
  3. python 之发送邮件服务[原著] 海瑞博客
  4. super和final关键字
  5. 异步fifo的设计(FPGA)
  6. Spring 笔记(一)概念梳理
  7. 解方程 sqrt(x-sqrt(n))+sqrt(y)-sqrt(z)=0的所有自然数解
  8. web浏览器中的javascript -- 2
  9. .export*读取图片
  10. Java9最受期待的5大新特性