LightOJ - 1118 (计算几何模板)
2017-08-31 18:58
369 查看
问题描述:
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.
![](https://odzkskevi.qnssl.com/6af80d419af02739276a8c8bc00e548e?v=1503871987)
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;
}
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;
}
相关文章推荐
- 计算几何二维模板
- 计算几何:规范相交模板
- 模板 2018-01-26 计算几何 平面 (超长 大概吧)
- 计算几何模板啦啦啦啦
- ACM计算几何模板
- 浅谈计算几何的模板集合
- 计算几何【套模板,推荐模板】 Separating Pebbles UVALive - 7461
- 计算几何的一些模板
- 计算几何模板
- 【lightoj1331】Agent J【计算几何】
- [模板仓库] 计算几何
- 计算几何模板2
- 【模板】计算几何--线段相交问题
- 计算几何小模板
- HDU 4998 Rotate(计算几何/绕弧度旋转/模板的巧用)
- 二维计算几何模板
- HDU 5572 An Easy Physics Problem (计算几何+模板)
- ACM计算几何知识点详解和模板代码2
- hihocoder #1040 矩形判断(计算几何问题 给8个点的坐标,能否成为一个矩形 【模板思路】)
- 计算几何模板