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;
}