HDU1798 Tell me the area(两圆的相交面积)

New~ 欢迎参加2016多校联合训练的同学们~
Tell me the area这里写链接内容

我的:
这个题虽然说是很简单,但是我觉得实现起来就有点麻烦,然后看了一下别人的代码,感觉某些人的这个格式挺好的,所以就借用了一下咯,谢谢这个哥们。

我的:

#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;
}c1,c2;

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()
{
   while(cin>>c1.x>>c1.y>>c1.r)
   {
       cin>>c2.x>>c2.y>>c2.r;
       printf("%.3lf\n",intersection_area(c1,c2));
   }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值