hdu 3264(二分+圆相交面积)
生活随笔
收集整理的這篇文章主要介紹了
hdu 3264(二分+圆相交面积)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給出一些圓,選擇其中一個圓的圓心為圓心,然后畫一個大圓,要求大圓最少覆蓋每個圓的一半面積。求最小面積。
解題思路:首先枚舉每個圓,以其圓心作為大圓的圓心,然后再用二分去尋找最小的半徑。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std;const int maxn = 20; const double eps = 1e-8; const double pi = 3.14159265; struct Circle {double x,y,r; }p[maxn]; int n; double dist(double x1,double y1,double x2,double y2) {return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }double Area(double x0,double y0,double radius,Circle p) {double d = dist(x0,y0,p.x,p.y);if(d >= radius + p.r) return 0;else if(d <= fabs(radius - p.r)) return min(radius,p.r) * min(radius,p.r) * pi;//計算兩個角度double a = acos((radius * radius + d * d - p.r * p.r) / (2 * radius * d));double b = acos((p.r * p.r + d * d - radius * radius) / (2 * p.r * d));return radius * radius * a + p.r * p.r * b - radius * d * sin(a); }bool Check(int k,double radius) {for(int i = 1; i <= n; i++)if(Area(p[k].x,p[k].y,radius,p[i]) < p[i].r * p[i].r * pi / 2.0)return false;return true; }int main() {int t;scanf("%d",&t);while(t--){scanf("%d",&n);double l,r,mid,ans = 9999999.0;for(int i = 1; i <= n; i++)scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);for(int i = 1; i <= n; i++) //枚舉圓心{l = 0, r = 500000;while(r - l > eps){mid = (l + r) / 2.0;if(Check(i,mid) == true){ans = min(ans,mid);r = mid;}else l = mid;}}printf("%.4f\n",ans);}return 0; }
總結
以上是生活随笔為你收集整理的hdu 3264(二分+圆相交面积)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: poj 2079(旋转卡壳)
- 下一篇: 九个Console命令,让 JS 调试更