题目链接:
Time Limit: 4000/4000 MS (Java/Others)
Memory Limit: 512000/512000 K (Java/Others)
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int N=1e5+6; const LL mod=1e9+7; const double PI=acos(-1.0); double fun(double x,double y,double fx,double fy,double r,double R) { double dis=sqrt((x-fx)*(x-fx)+(y-fy)*(y-fy)); //cout<<dis<<endl; if(dis>=r+R)return 0; else if(dis<=R-r) { return PI*r*r; } else { double angle1,angle2,s1,s2,s3,s; angle1=acos((r*r+dis*dis-R*R)/(2*r*dis)); angle2=acos((R*R+dis*dis-r*r)/(2*R*dis)); s1=angle1*r*r;s2=angle2*R*R; s3=r*dis*sin(angle1); s=s1+s2-s3; return s; } } int main() { int t; scanf("%d",&t); double r,R,x,y,fx,fy; int cnt=1; while(t--) { scanf("%lf%lf",&r,&R); scanf("%lf%lf%lf%lf",&x,&y,&fx,&fy); double ans1,ans2,ans3,ans4; ans1=fun(x,y,fx,fy,R,R); ans2=fun(x,y,fx,fy,r,r); ans3=fun(x,y,fx,fy,r,R); ans4=fun(fx,fy,x,y,r,R); printf("Case #%d: ",cnt++); printf("%.6lf\n",ans1+ans2-ans3-ans4); } }
原文:http://www.cnblogs.com/zhangchengc919/p/5451432.html