LightOJ 1118 - Incredible Molecules (两圆面积交)
2013-10-15 19:37
281 查看
1118 - Incredible Molecules
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
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.
http://lightoj.com/volume_showproblem.php?problem=1118
很简单,作为模板了
PDF (English) | Statistics | Forum |
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
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 | Output for Sample Input |
3 0 0 10 15 0 10 -10 -10 5 0 -10 10 100 100 20 100 110 20 | Case 1: 45.3311753978 Case 2: 35.07666099 Case 3: 860.84369 |
很简单,作为模板了
/* *********************************************** Author :kuangbin Created Time :2013-10-15 18:56:20 File Name :E:\2013ACM\专题强化训练\计算几何\LightOJ1118.cpp ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); struct Point { double x,y; void input() { scanf("%lf%lf",&x,&y); } }; double dist(Point a,Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } //两个圆的公共部分面积 double Area_of_overlap(Point c1,double r1,Point c2,double r2) { double d = dist(c1,c2); if(r1 + r2 < d + eps)return 0; if(d < fabs(r1 - r2) + eps) { double r = min(r1,r2); return PI*r*r; } double x = (d*d + r1*r1 - r2*r2)/(2*d); double t1 = acos(x / r1); double t2 = acos((d - x)/r2); return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1); } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); Point c1,c2; double r1,r2; int T; scanf("%d",&T); int iCase = 0; while(T--) { iCase ++; c1.input(); scanf("%lf",&r1); c2.input(); scanf("%lf",&r2); printf("Case %d: %.6lf\n",iCase,Area_of_overlap(c1,r1,c2,r2)); } return 0; }
相关文章推荐
- 【AA】SQL学习笔记(二)
- UVA 1438 - Asteroids(三维凸包)
- AD10画板细节
- 求两个电阻并联后的阻值
- 文档模式和浏览器模式
- 【税务基础知识】--很实用的常识
- Android中include和merge标签的使用(附源码)
- 关于uboot中tftp上传内存数据到tftp服务器
- jfinal 小例子
- check record lock
- 输出星号图
- MyEclipse安装插件的几种方法
- 滤镜之像素化Pixelate
- android中文字中间有超链接的实现方法
- C# Tips: ICloneable<T>
- Altium Designer 10.0安装破解笔记
- 黑马程序员--JAVA交通灯管理系统项目
- 电子邮件恢复1--恢复原理
- RSA hdu 1211 数论的水题(数据较弱)
- 纠正从小的认识错误[关于闰年的判断]