hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径。

对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define pi acos(-1.0)
#define eps 1e-8
#define maxn 50
int n;
struct point{
    double x;
    double y;
    double r;
}c[maxn];
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 area(point a,double ra,point b,double rb)
{
    double ans=0;
    double d=dis(a,b);
    double temp;
    if(ra<rb)  swap(ra,rb);
    if(d>=ra+rb)return 0;
    if(d<=ra-rb)return pi*rb*rb;
    double angle1=acos((ra*ra+d*d-rb*rb)/2.0/ra/d);
    double angle2=acos((rb*rb+d*d-ra*ra)/2.0/rb/d);
    ans-=d*ra*sin(angle1);
    ans+=angle1*ra*ra+angle2*rb*rb;
    return ans;
}
bool cover_half(point a,double ra,point b,double rb)  //a是有伞的圆,b是其他圆
{
    return area(a,ra,b,rb)>=0.5*rb*rb*pi;
}
bool isok(double r,int k)
{
    for(int i=1;i<=n;i++)
    {
        if(!cover_half(c[k],r,c[i],c[i].r)) return false;
    }
    return true;
}
int main()
{
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
        }
        double ans=5000000;
        for(int i=1;i<=n;i++){
            double l=0.0,r=5000000,mid;
            while(l+eps<=r)
            {
                mid=(l+r)/2;
                if(isok(mid,i)) r=mid-eps;
                else l=mid+eps;
            }
            ans=min(ans,mid);
        }
        printf("%.4lf\n",ans);
    }
    return 0;
}

hdu 3264 Open-air shopping malls 求两圆相交,布布扣,bubuko.com

时间: 2024-08-02 02:43:03

hdu 3264 Open-air shopping malls 求两圆相交的相关文章

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

题目链接: POJ:http://poj.org/problem?id=2546 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three di

求两圆相交部分面积(C++)

已知两圆圆心坐标和半径,求相交部分面积: 1 #include <iostream> 2 using namespace std; 3 #include<cmath> 4 #include<stdio.h> 5 #define PI 3.141593 6 struct point//点 7 { 8 double x,y; 9 }; 10 struct circle//圆 11 { 12 point center; 13 double r; 14 }; 15 float

hdu 5120 (求两圆相交的面积

题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue> #include<set&

hdu 5120 (求两圆相交的面积的公式)

S = A大B大 - A大B小 - A小B大 + A小B小.(A表示A环,大表示大圆,B同).然后直接套模板,,,, 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <cmath> 5 using namespace std; 6 7 const double eps = 1e-8; 8 const double PI = acos(-1.0); 9 1

求两圆相交的面积

走自己的路,你会发现,在走的过程中你会收获很多 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <limits.h> #include <ctype.h> #include <string.h> #include <string> #include <algorithm> #include <iostream>

求两圆相交面积模板

#define PI 3.141592654 #define eps 1e-8 double getdis(int x1,int y1,int x2,int y2){ return sqrt((double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } double getarea(int x1,int y1,double r1,int x2,int y2,double r2){ double d=getdis(x1,y1,x2,y2); if(r1+r2<d+eps)

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is

poj 2546 Circular Area (两圆相交面积)

链接:poj 2546 题意:已知两圆的圆心和半径,求两圆相交部分的面积 分析:两圆的位置关系有三种:相离,相交,内含 相离时:相交面积为0 相交时,大扇形面积+小扇形面积-四边形面积 内含时,相交面积为小圆面积 #include<stdio.h> #include<math.h> #define PI acos(-1.0) typedef struct stu { double x,y; }point; double Distance(point a,point b) { ret

poj2546Circular Area(两圆相交面积)

链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; #include<cmath> #include<iomanip> #include<algorithm> int main() { double d,t,t1,s,x,y,xx,yy,r,rr; while(cin>>x>>y>>r) {