1118 - Incredible Molecules
 
Time Limit: 0.5 second(s) Memory Limit: 32 MB

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

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

首先,判断两圆关系,如果相交(两个交点),则求出相交的面积,外离和外切相交面积为0.

 #include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
const double PI = acos(-1.0);
typedef struct point {
double x;
double y;
point() { }
point(double a, double b) {
x = a;
y = b;
}
friend istream& operator >> (istream& in, point&b) {
in >> b.x >> b.y;
return in;
}
point operator -(const point &b)const {
return point(x - b.x, y - b.y);
}
point operator +(const point &b)const {
return point(x + b.x, y + b.y);
}
point operator *(const double &k)const {
return point(x * k, y * k);
}
point operator /(const double &k)const {
return point(x / k, y / k);
}
double operator ^(const point &b)const {
return x*b.y - y*b.x;
}
double operator *(const point &b)const {
return x*b.x + y*b.y;
}
}point;
typedef struct circle {
double r;
point centre;
friend istream& operator >> (istream &in, circle &b) {
in >> b.centre >> b.r;
return in;
}
double area() {
return PI*r*r;
}
}circle;
double dist(point p1, point p2) {
return sqrt((p1 - p2)*(p1 - p2));
}
void CircleInterArea(circle a, circle b, double &s1, double &s2) {//相交面积
double d = dist(a.centre, b.centre);//圆心距
double t = (d*d + a.r*a.r - b.r*b.r) / (2.0 * d);//
double h = sqrt((a.r*a.r) - (t*t)) * ;//h1=h2
double angle_a = * acos((a.r*a.r + d*d - b.r*b.r) / (2.0 * a.r*d));
//余弦公式计算r1对应圆心角,弧度
double angle_b = * acos((b.r*b.r + d*d - a.r*a.r) / (2.0 * b.r*d));
//余弦公式计算r2对应圆心角,弧度
double la = angle_a*a.r;//r1所对应的相交弧长
double lb = angle_b*b.r;//r2所对应的相交弧长
s1 = la*a.r / 2.0 - a.r*a.r*sin(angle_a) / 2.0; //相交部分r1圆的面积
s2 = lb*b.r / 2.0 - b.r*b.r*sin(angle_b) / 2.0; //相交部分r2圆的面积
//double rest_s1 = PI*a.r*a.r - s1 - s2;//r1圆剩余部分面积,不含相交部分面积
//double rest_s2 = PI*b.r*b.r - s1 - s2;//r1圆剩余部分面积,不含相交部分面积
}
//两圆关系
int CircleInterNum(circle a, circle b) {
double fh = fabs(a.r + b.r), fc = fabs(a.r - b.r), d = dist(a.centre, b.centre);
if (d>fh)
return -; //外离,没有交点
if (d == fh)
return -; //外切,一个交点
if (d > fc&&d < fh)
return ; //相交,两个交点
if (d == fc)
return ; //内切,一个交点
if (d < fc&&d >= )
return ; //内含,没有交点
}
int main(void) {
int t;
cin >> t;
for (int i = ; i <= t; i++) {
circle c1, c2;
double s1, s2;
cin >> c1 >> c2;
int f = CircleInterNum(c1, c2);
if (f == ) {
CircleInterArea(c1, c2, s1, s2);
printf("Case %d: %.8f\n", i, s1 + s2);
}
else if (f == - || f == -) {
printf("Case %d: 0\n", i);
}
else if (f == || f == ) {
printf("Case %d: %.8f\n", i,min(c1.area(),c2.area()));
}
}
return ;
}

LightOJ 1118--Incredible Molecules(两圆相交)的更多相关文章

  1. LightOJ 1118 - Incredible Molecules (两圆面积交)

    1118 - Incredible Molecules   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: ...

  2. LightOj 1118 - Incredible Molecules(两圆的交集面积)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1118 给你两个圆的半径和圆心,求交集的面积: 就是简单数学题,但是要注意acos得到的 ...

  3. POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

    题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...

  4. 两圆相交求面积 hdu5120

    转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...

  5. 求两圆相交部分面积(C++)

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

  6. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. poj2546Circular Area(两圆相交面积)

    链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...

  8. hdu 5120 (求两圆相交的面积

    题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...

  9. [hdu 3264] Open-air shopping malls(二分+两圆相交面积)

    题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右 ...

随机推荐

  1. Intellij IDEA快捷键大全汇总

    Alt+回车 导入包,自动修正 Ctrl+N   查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L  格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码 ...

  2. C语言——顺序表插入、删除、定位运算算法

    说明:将元素x插入到顺序表L的第i个数据元素之前,这个i是从1开始的,但是程序中数组都是从0算起的,不要混淆了. 头文件: header.h // 顺序表的结构定义 #define Maxsize 1 ...

  3. 【统计学】英文概念之Mean和Average的区别

    通过专门检索和其他课本的比较,得到了如下结论.统计学在分析数据时,需要对数据进行最基础的描述性分析.在众多描述分析的指标中,平均数指标能够反映分布数列集中趋势.但是平均数指标包括两类:一类是数值平均数 ...

  4. Android菜单(动画菜单、360波纹菜单)

     Android菜单(动画菜单.360波纹菜单) 前言:Android菜单常用集合:FragmentTabHost系统菜单.上移式菜单.360波纹菜单.展开式菜单.详解注释,可直接拿来用! 效果:   ...

  5. SQA和系统测试规程

    1.SQA计划 (1)目的 本计划是定义Online Judge(在线测评系统)项目的SQA组织,SQA任务和职责,项目过程中应遵循的流程.规范和约定等,指导SQA人员进行评审和审计活动,验证项目的产 ...

  6. Subversion FAQ(常见问题解答)

    转自:http://subversion.apache.org/faq.zh.html 常见问题: 为什么会有这样一个项目? 为了接管CVS的用户基础.确切的说,我们写了一个新的版本控制系统,它和CV ...

  7. Eclipse编码格式

    来源:http://e-ant.javaeye.com/blog/177579 如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Java文件使用UTF-8编码.然而,E ...

  8. hexo安装-nodejs

    npm- 安装淘宝源 http://npm.taobao.org/$ npm install -g cnpm --registry=https://registry.npm.taobao.org- 查 ...

  9. 哈夫曼树算法及C++实现

    一.相关概念 1.叶子结点的权值(weight)是对叶子结点赋予的一个有意义的数值量. 2.设二叉树有n个带权值的叶子结点,从根节点到各个叶子结点的路径长度与相应叶子结点权值的乘积之和叫做二叉树的带权 ...

  10. .Net深入体验与实践第一章

    什么是委托?委托和事件是什么关系? 我的理解是委托朋友,事件是一个事情比如,中午12点要吃饭了,咱家搞忘了!还在继续嗨皮,我的朋友会叫我与他一起吃饭. 什么事反射? 可以获取.Net中的每个类型(类, ...