2013
12-23

# Tell me the area

There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.

There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.

For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.

0 0 2
2 2 1

0.108

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
double x1,y1,r1,x2,y2,r2,s,PI;
PI=2*asin(1.0);                //PI不能写成3.1415926
while(cin>>x1>>y1>>r1)
{
cin>>x2>>y2>>r2;

double d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
if(d>=(r1+r2)||!r1||!r2)      //外离
s=0;
else if(d<=abs(r2-r1))        //内含
{
if(r2<r1)
r1=r2;
s=r1*r1*PI;
}
else                                   //相交
{
double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));       //a1,a2分别为两扇形圆心角的一半
double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
s=a1*r1*r1+a2*r2*r2-r1*r1*sin(a1)*cos(a1)-r2*r2*sin(a2)*cos(a2);        //相交面积等于两扇形面积之和减四边形

}
printf("%.3lf\n",s);
}

return 0;
}

1. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。

2. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！

3. int half(int *array,int len,int key)
{
int l=0,r=len;
while(l<r)
{
int m=(l+r)>>1;
if(key>array )l=m+1;
else if(key<array )r=m;
else return m;
}
return -1;
}
这种就能避免一些Bug
l,m,r
左边是l,m;右边就是m+1,r;

4. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮

5. “可以发现,树将是满二叉树,”这句话不对吧，构造的树应该是“完全二叉树”，而非“满二叉树”。

6. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks