lightoj1118 Incredible Molecules

思路:求两个圆相互遮盖的面积,对于圆的位置情况有外切,内切,相离,内含,相交。

这里需要考虑的是(相离+外切),相交,内含(两种情况);

手推了下公式,,刚入门,,,推得有点慢。

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值