LightOJ
来源:互联网 发布:马其顿 知乎 编辑:程序博客网 时间:2024/06/01 08:11
问题描述:
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.
OutputFor 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 OutputCase 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;}
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- [LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- 10.内部类
- 关于锁的理解
- git tag教程
- 【HUSTOJ】1092: 马鞍数
- Java多线程学习
- LightOJ
- Gym
- C++ 直接选择排序的实现实例代码
- 指向多维数组的指针
- Spark特性之共享变量
- Tomcat下使用Druid配置JNDI数据源
- 第4部分库与运行库(第10章 内存)
- H5表单相关新增元素和属性
- 赏析ReentrantLock源码