HDU 1798 Tell me the area (数学)
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 (数学)的更多相关文章
- HDU 1798 Tell me the area
http://acm.hdu.edu.cn/showproblem.php?pid=1798 Problem Description There are two circles in the ...
- HDU 1071 The area (数学定积分)
题意:求阴影部分面积. 析:没什么可说的,就是一个普通的定积分. 代码如下: #include <cstdio> #include <iostream> using names ...
- HDU 4342——History repeat itself——————【数学规律】
History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...
- hdu 1597 find the nth digit (数学)
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 6659 Acesrc and Good Numbers (数学 思维)
2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...
- HDU 5019 Revenge of GCD(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...
- HDU 5476 Explore Track of Point 数学平几
Explore Track of Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4091 /** 这题的一种思路就是枚举了: 基于这样一个事实:求出lcm = lcm(s1,s2), n ...
- HDU 4099 Revenge of Fibonacci (数学+字典数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头 ...
随机推荐
- 零基础学习Vim编辑器
**********************************************************************0.这篇教程的简介:Vim是Linux/Unix下的经典编辑 ...
- jmeter的基本使用过程
jmeter的基本使用过程 接下来几周,我将通过视频的方式,录制下来jmeter的基本用法,方便大家参考学习 可能导图会随时调整
- libvirt保持虚拟机运行情况下修改名称
通过virsh list命令能看到虚拟机的列表: [root@compute2 ~]# virsh list Id 名称 状态 ------------------------------------ ...
- Hexo 博客部署到 GitHub
本文简单记录了一下把 Hexo 部署到 GitHub 上的过程,也是搭建静态博客最常用的一种方式. 前面写了关于如何把 Hexo 安装在树莓派上的教程,但树莓派毕竟是连着自己的家的路由器,万一哪天网断 ...
- Python时间获取及转换知识汇总
时间处理是我们日常开发中最最常见的需求,例如:获取当前datetime.获取当天date.获取明天/前N天.获取当天开始和结束时间(00:00:00 23:59:59).获取两个datetime的时间 ...
- OJ题归纳
1.求最大公约数 利用辗转相除法求最大公约数 int gcd(int a,int b) { int c,r; if(a<b){c=a;a=b;b=c;} if(b==0) return a; r ...
- 实现AJAX跨域访问方式一
1.添加pom依赖 <dependency> <groupId>com.thetransactioncompany</groupId> <artifactId ...
- WCF服务全局异常处理机制
服务端增加WCF服务全局异常处理机制,任一WCF服务或接口方式出现异常,将统一调用WCF_ExceptionHandler.ProvideFault方法,因此不需要每个方法使用try catch写法. ...
- VS 附加进程调试
1.在IIS 上新建一个项目,制定目录到 项目根目录. 2.制定IIS上指定 主机名称如: vk.com 3. 修改主机HOST 文件:C:\Windows\System32\drivers\etc ...
- 全局 Ajax 事件处理器
jQuery中将Ajax请求和响应分成了若干(5)个阶段 并且允许开发者在Ajax请求和响应的不同阶处理不同的逻辑, 这些方法用于注册事件处理器,用来处理页面上的任何 Ajax 请求,当某些事件触发后 ...