Returns the area of the intersection of two circles.
Take your own path and you will find that you will gain a lot in the process
#include
#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
#include
#include
#include
#include
using namespace std;double dis(int x1,int y1,int x2,int y2){ double len = sqrt((x1-x2+0.0)*(x1-x2+0.0)+(y1-y2+0.0)*(y1-y2+0.0)); return len;}double f(int x1,int y1,int r1,int x2,int y2,int r2){ double a = dis(x1,y1,x2,y2), b = r1+0.0, c = r2+0.0;double cta1 = acos((a * a + b * b - c * c) / 2 / (a * b)),cta2 = acos((a * a + c * c - b * b) / 2 / (a * c));double s1 = (r1+0.0)*r1*cta1 - (r1+0.0)*r1*sin(cta1)*(a * a + b * b - c * c) / 2 / (a * b);double s2 = (r2+0.0)*r2*cta2 - (r2+0.0)*r2*sin(cta2)*(a * a + c * c - b * b) / 2 / (a * c);return s1 + s2;}int main(){ int x1,y1,x2,y2,r1,r2; while(~scanf("%d%d%d%d%d%d",&x1,&y1,&r1,&x2,&y2,&r2)){ double ans = f(x1,y1,r1,x2,y2,r2); printf("%.4lf\n",ans); } return 0;}