题目链接

Problem Description

There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.

Input

There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.

Output

For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.

Sample Input

0 0 2
2 2 1

Sample Output

0.108

分析:

两圆的位置关系有相离、相切和相交三种,相切又有外切和内切。

如果两圆的位置关系是相离或者外切的话,它们是没有公共部分的,及面积为0;

如果两圆内切,公共部分就为整个的小圆,面积也就是小圆的面积;

如果两圆相交的话,面积就应该是每个圆所对应的扇形减去所对应的三角形的面积和。

代码:

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double q,w,m,n,a,b,c,x,y,z,PI;
PI=2*asin(1.0);
while(~scanf("%lf%lf%lf",&a,&b,&c))
{
scanf("%lf%lf%lf",&x,&y,&z);
a=sqrt((a-x)*(a-x)+(b-y)*(b-y));///计算圆心距
///如果两圆相离、外切或至少一圆半径为0时,那么所求面积为0
if(a>=c+z||!c||!z)x=0;
///如果两内切或内含,那么所求面积为小圆面积
else if(a<=fabs(z-c))
{
if(z>c)z=c;
x=z*z*PI;
}
///如果两圆相交,面积求解如下
else
{
///由余弦定理求出公共弦在圆o1中对应的圆心角的一半
b=acos((a*a+c*c-z*z)/(2*a*c));
///由余弦定理求出公共弦在圆o2中对应的圆心角的一半
y=acos((a*a+z*z-c*c)/(2*a*z));
///计算圆o1中扇形面积
m=b*c*c;
///计算圆o2中扇形面积
n=y*z*z;
///计算圆o1中扇形所对应的三角形面积
q=c*c*sin(b)*cos(b);
///计算圆o2中扇形所对应的三角形面积
w=z*z*sin(y)*cos(y);
///q+w为图中四边形面积,两扇形面积之和与四边形面积之差即为
///所求面积。在图2中y为钝角,计算出的面积w为负值,这时q+w
///表示两三角面积之差,刚好还是四边形面积,因此对于图1和图
///2不必分情况讨论
x=m+n-(q+w);
}
printf("%.3f\n",x);
}
return 0;
}

HDU 1798 Tell me the area (数学)的更多相关文章

  1. HDU 1798 Tell me the area

    http://acm.hdu.edu.cn/showproblem.php?pid=1798 Problem Description     There are two circles in the ...

  2. HDU 1071 The area (数学定积分)

    题意:求阴影部分面积. 析:没什么可说的,就是一个普通的定积分. 代码如下: #include <cstdio> #include <iostream> using names ...

  3. HDU 4342——History repeat itself——————【数学规律】

    History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  4. hdu 1597 find the nth digit (数学)

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. HDU 6659 Acesrc and Good Numbers (数学 思维)

    2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...

  6. HDU 5019 Revenge of GCD(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...

  7. HDU 5476 Explore Track of Point 数学平几

    Explore Track of Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  8. hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4091 /** 这题的一种思路就是枚举了: 基于这样一个事实:求出lcm = lcm(s1,s2), n ...

  9. HDU 4099 Revenge of Fibonacci (数学+字典数)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头 ...

随机推荐

  1. OSI七层模型加协议

    OSI七层网络模型 TCP/IP四层概念模型 对应网络协议 应用层(Application) 应用层 HTTP.TFTP, FTP, NFS, WAIS.SMTP 表示层(Presentation) ...

  2. mcrouter facebook 开源的企业级memcached代理

    原文地址:https://code.facebook.com/posts/296442737213493/introducing-mcrouter-a-memcached-protocol-route ...

  3. C++学习008-delete与delete[]的差别

    对于简单的数据类型,delete与delete[]是没啥差别的,就是等价的 例如 int main() { int *pdata = new int[20]; delete pdata; //dele ...

  4. SVN脱离锁定的几种方法

    SVN经常出现被锁定而无法提交的问题,选择解锁又提示没有文件被锁定,很是头疼.这里整理了一下SVN 被锁定的几种解决方法: 1.出现这个问题后使用“清理”即"Clean up"功能 ...

  5. 重写selenium 的 click()操作,使其变成隐式等待

    selenium 页面常会因为页面加载慢而出现element 不能被点击到的情况,比如加载过程中出现遮罩,导致element 可见不可点.以下方法重写click(),用隐式等待解决这个问题. 基本思路 ...

  6. Selenium Grid 环境搭建 碰到的unable to access server

    1. Slenenium Grid的环境部署, 前提条件: JDK,JRE都已经安装, selenium的standalone jar包放在磁盘 执行如下命令,报错: 2. 在cmd窗口里切换到jar ...

  7. Python 套接字的使用 (1)

    获取设备名称和IPv4地址 socket.gethostname() socket.gethostbyname(host_name)   def print_machine_info(): host_ ...

  8. 梳理 Opengl ES 3.0 (二)剖析一个GLSL程序

    OpenGL ES shading language 3.0 也被称作 GLSL,是个 C风格的编程语言. Opengl ES 3.0内部有两种可编程处理单元,即Vertex processor和Fr ...

  9. Python 学习笔记之—— PIL 库

    PIL,全称 Python Imaging Library,是 Python 平台一个功能非常强大而且简单易用的图像处理库.但是,由于 PIL 仅支持到Python 2.7,加上年久失修,于是一群志愿 ...

  10. 软件工程项目组Z.XML会议记录 2013/10/22

    软件工程项目组Z.XML会议记录 [例会时间]2013年10月22日星期二21:00-22:30 [例会形式]小组讨论 [例会地点]三号公寓楼会客厅 [例会主持]李孟 [会议记录]周敏轩 会议整体流程 ...