HDU5120Intersection(两圆环相交的面积)

HDU5120Intersection(两圆环相交的面积)这里写链接内容

我的:
这个是两个圆环相交的面积,题意是:给出两个同心的圆环,他们的小圆大圆的半径都一样,只是坐标不相等,之后要求求两个圆环的相交的面积,这个要套用利用到两个圆的相交面积的一个模板,感觉很流畅。
之后再利用这个关系式:
Area圆环==intersection_area圆环A的大圆&圆环B的大圆-intersection_area圆环A的大圆&圆环B的小圆-intersection_area圆环A的小圆&圆环B的大圆+intersection_area圆环A的小圆&圆环B的小圆圆。

我的:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>

#define PI acos(-1.0)

using namespace std;
const int maxn=100000+10;


struct Circle
{
    double x,y;
    double r;
}ca,cb,cc,cd;

double intersection_area(Circle c1,Circle c2)//求两圆相交面积的函数
{
    double d;
    double angle1,angle2,s1,s2,s3,s,temp;
    d=sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
//    cout<<d<<endl;
    if(d>=c1.r+c2.r)
        return 0;
    if(c1.r-c2.r>=d)
        return PI*c2.r*c2.r;
    if(c2.r-c1.r>=d)
        return PI*c1.r*c1.r;
    angle1=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    angle2=acos((c2.r*c2.r+d*d-c1.r*c1.r)/(2*c2.r*d));
    s1=c1.r*c1.r*angle1;
    s2=c2.r*c2.r*angle2;
    s3=c1.r*d*sin(angle1);
//    cout<<c1.r<<" "<<d<<' '<<sin(angle1)<<endl;
//    cout<<angle1<<" "<<angle2<<" "<<s1<<" "<<s2<<" "<<s3<<endl;
    s=s1+s2-s3;
    return s;
}


int main()
{
   int time;
   scanf("%d",&time);
   int k=0;
   while(time--)
   {
       k++;
       scanf("%lf%lf",&ca.r,&cb.r);
       scanf("%lf%lf",&ca.x,&ca.y);
       scanf("%lf%lf",&cc.x,&cc.y);
       cc.r=ca.r;
       cd.r=cb.r;
       cb.x=ca.x;
       cb.y=ca.y;
       cd.x=cc.x;
       cd.y=cc.y;
       double area=intersection_area(cb,cd)-intersection_area(ca,cd)-intersection_area(cb,cc)+intersection_area(ca,cc);
      printf("Case #%d: %.6llf\n",k,area);
   }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值