LightOJ - 1118 (计算几何模板)

问题描述:

In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There are some circular molecules, when two of them collide, they overlap with each other, and it's hard to find that which one is over the other one.

Given two molecules as circles, you have to find the common area of the given molecules that is shaded in the picture.


Input

Input starts with an integer T (≤ 12), denoting the number of test cases.

Each case contains six integers x1, y1, r1 and x2, y2, r2. Where (x1, y1) is the center of the first molecule and r1 is the radius and (x2, y2) is the center of the second molecule and r2 is the radius. Both the radiuses are positive. No integer will contain more than 3 digits.

Output

For each test case, print the case number and the common area of the given molecules. Errors less than 10-6 will be ignored.

Sample Input

3

0 0 10 15 0 10

-10 -10 5 0 -10 10

100 100 20 100 110 20

Sample Output

Case 1: 45.3311753978

Case 2: 35.07666099

Case 3: 860.84369


题目题意:题目给我们俩给圆的圆心坐标和半径,让我们求出相交的面积。

题目分析:直接根据几何知识来算出面积的表达式(挺简单的),自己可以存下来,以后可以用.

代码如下:

#include<iostream>
#include<cmath>
#include<cstdio>
#define pi acos(-1.0)
using namespace std;

typedef struct node
{
	int x;
	int y;
}point;

double AREA(point a, double r1, point b, double r2)//模板
{
	double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
	if (d >= r1+r2)
		return 0;
	if (r1>r2) swap (r1,r2);
	if(r2 - r1 >= d)
		return pi*r1*r1;
	double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
	double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
	return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}

int main()
{
	point a, b;
	int r1,r2,icase=1,t;
	scanf("%d",&t);
	while (t--) {
    scanf("%d%d%d%d%d%d",&a.x,&a.y,&r1,&b.x,&b.y,&r2);
	double re = AREA(a, r1, b, r2);
	printf("Case %d: %.8lf\n", icase++,re);
	}
	return 0;
}












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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值