思路:求两个圆相互遮盖的面积,对于圆的位置情况有外切,内切,相离,内含,相交。
这里需要考虑的是(相离+外切),相交,内含(两种情况);
手推了下公式,,刚入门,,,推得有点慢。
// #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <algorithm> #include <iomanip> #include <sstream> #include <string> #include <stack> #include <queue> #include <deque> #include <vector> #include <map> #include <set> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <climits> using namespace std; // #define DEBUG #ifdef DEBUG #define debug(...) printf( __VA_ARGS__ ) #else #define debug(...) #endif #define CLR(x) memset(x, 0,sizeof x) #define MEM(x,y) memset(x, y,sizeof x) #define pk push_back template<class T> inline T Get_Max(const T&a,const T&b){return a < b?b:a;} template<class T> inline T Get_Min(const T&a,const T&b){return a < b?a:b;} typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> ii; const double eps = 1e-10; const int inf = 1 << 30; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; struct Point{ double x, y; Point(){} Point(double _x, double _y){ x = _x; y = _y; } Point operator + (const Point& rhs)const{ return Point(x + rhs.x, y + rhs.y); } Point operator - (const Point& rhs)const{ return Point(x - rhs.x, y - rhs.y); } double operator ^ (const Point& rhs)const{ return (x * rhs.y - y * rhs.x); } double operator * (const Point& rhs)const{ return (x * rhs.x + y * rhs.y); } Point operator * (const double Num)const{ return Point(x * Num,y * Num); } friend ostream& operator << (ostream& output,const Point& rhs){ output << "(" << rhs.x << "," << rhs.y << ")"; return output; } }; typedef Point Vector; /*向量的模*/ inline double Length(const Vector& A){//Get the length of vector A; return sqrt(A * A);//sqrt(x*x+y*y); } /*向量夹角*/ inline double Angle(const Vector& A,const Point& B){ return acos(A * B/Length(A)/Length(B)); } /*向量A旋转rad弧度*/ inline Point Rotate(const Vector& A, double rad){ return Vector(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad)); } double mul(double x){ return x*x; } Point A,B; double R,r; const double PI = acos(-1.0); int main() { // ios::sync_with_stdio(false); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int t, icase = 0; cin >> t; while(t--){ cin >> A.x >> A.y >> R; cin >> B.x >> B.y >> r; double l = Length(A - B); if (l >= R + r){ printf("Case %d: 0\n", ++icase); continue; }//像离 if (l + r <= R && R >= r){ // debug("Cao\n"); printf("Case %d: %.6lf\n", ++icase, PI*r*r); continue; }//内含 if (l + R <= r && r >= R){ // debug("here\n"); printf("Case %d: %.6lf\n", ++icase, PI*R*R); continue; }//内含 double a1 = acos((mul(R) + mul(l) - mul(r))/2.0/R/l); double a2 = acos((mul(l) + mul(r) - mul(R))/2.0/r/l); double s = a1*R*R + a2*r*r - (R*R*sin(2*a1)/2.0 + r*r*sin(2*a2)/2.0); printf("Case %d: %.6lf\n", ++icase, s); } return 0; }