hdu 3264 圆的交+二分
Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1822 Accepted Submission(s): 651
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.
2
0 0 1
2 0 1
题目大意:给n个圆,求以某个圆的圆心为圆心作圆它与所有圆的交都大于等于圆面积一半的最小半径。
思路:枚举圆心二分找答案。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const double eps=1e-;
const double Pi=acos(-1.0);
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
typedef Point Vector;
Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量的长度
inline double min(double a,double b){return a>b?b:a;}
const int maxn=;
int n;
struct circle
{
Point c;
double r;
}C[maxn]; double getarea(int id,int i,double r)
{
double clen=Length(C[id].c-C[i].c);
if(clen>=r+C[i].r) return ;
double t=min(r,C[i].r);
if(clen<=fabs(r-C[i].r)) return Pi*t*t;
double ang1=acos((r*r+clen*clen-C[i].r*C[i].r)/(*r*clen));
double ang2=acos((C[i].r*C[i].r+clen*clen-r*r)/(*C[i].r*clen));
double area=ang1*r*r+ang2*C[i].r*C[i].r;
area-=sin(ang2)*C[i].r*clen;
return area;
} bool judge(int id,double r)
{
for(int i=;i<n;i++)
{
double area=getarea(id,i,r);
if(Pi*C[i].r*C[i].r>*area)
return false;
}
return true;
} double binary_search(double l,double r,int id)
{
double mid;
while(r-l>eps)
{
mid=(l+r)/2.0;
if(judge(id,mid)) r=mid;
else l=mid;
}
return l;
} void solve()
{
double ans=;
for(int i=;i<n;i++)
ans=min(ans,binary_search(,,i));
printf("%.4lf\n",ans);
}
int main()
{
int i,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%lf%lf%lf",&C[i].c.x,&C[i].c.y,&C[i].r);
solve();
}
return ;
}
hdu 3264 圆的交+二分的更多相关文章
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3511 圆扫描线
找最深的圆,输出层数 类似POJ 2932的做法 圆扫描线即可.这里要记录各个圆的层数,所以多加一个维护编号的就行了. /** @Date : 2017-10-18 18:16:52 * @FileN ...
- hdu 5111 树上求交
hdu 5111 树上求交(树链剖分 + 主席树) 题意: 给出两棵树,大小分别为\(n1\),\(n2\), 树上的结点权值为\(weight_i\) 同一棵树上的结点权值各不相同,不同树上的结点权 ...
- HDU 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 3264 Open-air shopping malls ——(二分+圆交)
纯粹是为了改进牛吃草里的两圆交模板= =. 代码如下: #include <stdio.h> #include <algorithm> #include <string. ...
- [hdu 3264] Open-air shopping malls(二分+两圆相交面积)
题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右 ...
- HDU - 6167: Missile Interception (二分+圆的交)
pro:二维平面上,给点N个导弹的初始位置,射出方向,速度.问你是找一点,可以从这一点向任意方向发出拦截导弹,速度未V,最小化最大拦截导弹的时间. 如果要拦截一个导弹,必须在导弹发射之后才可以发射拦 ...
- 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 ...
- hdu 3264(枚举+二分+圆的公共面积)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- QT5:介绍
一.简介 QT是一个跨平台的C++开发库,主要用来开发图形用户界面(Graphical User Interface,GUI) QT除了可以绘制漂亮的界面(包括控件/布局/交互),还可以多线程/访问数 ...
- 在Scrollview中使用AutoLayout
AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大 ...
- python特殊字符转义符号表示
- JWT (JSON WEB Token)正确使用场景
https://www.jianshu.com/p/af8360b83a9f 讲真,别再使用JWT了! ThoughtWorks中国 2017.08.16 08:51* 字数 2882 阅读 7154 ...
- 11Vim文本编辑器
Vim文本编辑器 在Linux系统中一切都是文件,而配置一个服务就是在修改其配置文件的参数. Vim提供了三种模式:命令模式.输入模式.末行模式 1.命令模式 每次运行Vim编辑器时,默认进入命令模式 ...
- 线段树:CDOJ1597-An easy problem C(区间更新的线段树)
An easy problem C Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest Moving On
Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn.Each city has a r ...
- 合肥工业大学宣城校区大学生创新创业训练项目申报书:“基于Spark平台的人工智能知识的知识图谱构建”
- Java常用api和操作必背
1.数组排序 Java的Arrays类(java.util中)包含用来操作数组(比如排序和搜索)的各种方法. Arrays.sort(各种类型数组) 2.数组转字符串 1)打印数组时可用Arrays. ...
- 求1+2+...+n 【微软面试100题 第十二题】
题目要求: 要求不能使用乘除法,for/while/if/else/switch/case等关键字以及条件判断语句(A?B:C). 参考资料:剑指offer第46题 题目分析: 方法1:利用类的静态成 ...