light oj 1118
来源:互联网 发布:视频教学软件 编辑:程序博客网 时间:2024/06/12 04:42
Description
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.
Overlapping Molecules
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
有时候用double 处理精度时很容易出错,可以直接用表达式表示
#include <iostream>
#include <cstdio>#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-7;
struct node
{
double x, y, r;
}p[4];
int main()
{
int t, ncase=1;
scanf("%d", &t);
while(t--)
{
scanf("%lf %lf %lf %lf %lf %lf",&p[1].x, &p[1].y, &p[1].r, &p[2].x,&p[2].y,&p[2].r);
if(p[1].r>p[2].r)
{
node tmp;
tmp=p[1], p[1]=p[2], p[2]=tmp;
}
double dist=sqrt((p[1].x-p[2].x)*(p[1].x-p[2].x)+(p[1].y-p[2].y)*(p[1].y-p[2].y));
double s=p[1].r+p[2].r;
if(dist>=s)
{
printf("Case %d: 0\n",ncase++);
}
else if(p[2].r>=dist+p[1].r)
{
printf("Case %d: %.10f\n",ncase++,pi*p[1].r*p[1].r);
}
else
{
double x=(p[1].r*p[1].r+dist*dist-p[2].r*p[2].r)/(2*p[1].r*dist);
double y=(p[2].r*p[2].r+dist*dist-p[1].r*p[1].r)/(2*p[2].r*dist);
double s=0.5*(p[1].r*dist)*sqrt(1-x*x);
double s1=(acos(x)/2)*(p[1].r*p[1].r);
double s2=(acos(y)/2)*(p[2].r*p[2].r);
double s3=(s1+s2-s)*2;
printf("Case %d: %.10f\n",ncase++,s3);
}
}
return 0;
}
- light oj 1118
- light oj 1118 Incredible Molecules
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- Light OJ Beginners Problems
- Light OJ Basic Geometry
- Light OJ Basic Math
- light oj 1124
- 论文笔记 | BoxSup: Exploiting Bounding Boxes to Supervise Convolutional Networks for Semantic Segmentati
- VPS CentOS 7搭建ss完整教程
- 调用相机并将照片存储到sd卡上
- python orm 之 sqlalchemy
- 【计算机组成原理】单周期处理器
- light oj 1118
- 今天我开通了CSDN博客
- Qt 之QToolButton 实现QQ界面按钮效果
- HDU 1711 Number Sequence(KMP模板)
- struts2.5框架使用通配符指定方法常见错误
- 杭电OJ 1097 A hard puzzle(我最后的博客水题报告)
- 为了忘却的纪念
- [Lintcode]Best Time to Buy and Sell Stock
- 服务端ecs使用mongodb