HDU 3264 Open-air shopping malls(圆的面积交+二分)
来源:互联网 发布:看股票行情用什么软件 编辑:程序博客网 时间:2024/05/17 09:02
题目链接:Click here~~
题意:
给你 n 个圆,作一个新的圆(以 n 个圆里面的一个圆心为圆心),要求将所有的圆覆盖至少一半的面积,求出最小半径。
解题思路:
主要是求圆的面积交,之后就可二分了。
大致思路是:用两个扇形的面积 - 四边形的面积。
#include <math.h>#include <stdio.h>#include <algorithm>using namespace std;const double eps = 1e-6;const double Pi = acos(-1.0);struct Point{ int x,y;};struct Circle{ Point center; double r;}A[22];int n;int sgn(double x){ return x<-eps ? -1 : (x>eps);}double Dis(const Point& p1,const Point& p2){ return sqrt( 1.0*(p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );}double Area(const Circle& c){ return Pi*c.r*c.r;}double CirInter(const Circle& c1,const Circle& c2){ double d = Dis(c1.center,c2.center); if(sgn(d-c1.r - c2.r) >= 0) return 0; if(sgn(fabs(c1.r - c2.r)-d) >= 0) return c1.r<c2.r ? Area(c1) : Area(c2); double a1 = acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d)); double a2 = acos((c2.r*c2.r+d*d-c1.r*c1.r)/(2*c2.r*d)); return a1*c1.r*c1.r + a2*c2.r*c2.r - c1.r*d*sin(a1);}bool can(double rr){ for(int i=0,j;i<n;i++) { Circle tmp = A[i]; tmp.r = rr; for(j=0;j<n;j++) if(CirInter(tmp,A[j]) < Area(A[j])/2) break; if(j == n) return true; } return false;}int main(){ int z; scanf("%d",&z); while(z--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d%lf",&A[i].center.x,&A[i].center.y,&A[i].r); double l = 0 , r = 1e6; while(sgn(r-l) > 0) { double mid = (l+r)/2; if(can(mid)) r = mid; else l = mid; } printf("%.4f\n",r); } return 0;}
- HDU 3264 Open-air shopping malls(圆的面积交+二分)
- HDU 3264 Open-air shopping malls (两个圆的交面积+二分)
- HDU 3264 Open-air shopping malls(二分+圆交)
- hdu - 3264 - Open-air shopping malls(二分 + 圆面积交)
- HDU 3264 Open-air shopping malls (计算两圆相交的面积 + 二分)
- hdu 3264 Open-air shopping malls 计算几何 相交圆的面积 二分
- hdu 3264 Open-air shopping malls(二分+两圆相交面积)
- [hdu 3264] Open-air shopping malls(二分+两圆相交面积)
- HDU 3264 Open-air shopping malls(圆相交面积+二分)
- HDU 3264 Open-air shopping malls(两圆相交公共部分面积 二分答案)
- HDU 3264 Open-air shopping malls [相交圆面积+二分查找]【计算几何】
- HDU 3264 Open-air shopping malls(二分查找)
- HDU3264 Open-air shopping malls (圆交+二分)
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
- HDU--3264[Open-air shopping malls] 枚举圆心+二分半径
- hdu3264 Open-air shopping malls(二分求最小半径覆盖所有圆的至少一半的面积)
- HDU 3264||POJ 3831 Open-air shopping malls【计算机几何】【圆相交面积模板】
- HDU 3264 - Open-air shopping malls
- C++新手必问之头文件
- 第12章 类 (part1) 类的定义和声明 & 类隐含的 this 指针
- 负载均衡算法
- getaddrinfo函数的使用
- 信息安全:防泄密软件设计构想与选型建议
- HDU 3264 Open-air shopping malls(圆的面积交+二分)
- 关于box—shadow
- jquery博客实现底部固定类似人人校内似的
- Merge into 详细介绍
- windows下逻辑备份脚本
- xapian安装使用
- HUD-4419 Colourful Rectangle 线段树+扫描线+离散
- 编写一个随内核加载的简单驱动
- sqlserver多行转一行