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多少的开头 ...
随机推荐
- js解决img标签加载失败显示默认图片
问题: 为所有显示楼盘的页面添加一个加载失败的默认图片. 基本思路: img标签中有个onerror属性,专门用来处理加载失败的事件.所以可以用jquery添加onerror属性,在onerror中加 ...
- oracle 数据库字段名与实体类字段名称不匹配的处理方法
之前公司一直都使用sql server 即使数据库字段名称与实体类名称不相同 可以使用诸如: select id as userId from tb_user 这种写法,可换到了oracle 之后坑爹 ...
- [POJ3585]Accumulation Degree
题面 \(\text{Solution:}\) 有些题目不仅让我们做树型 \(\text{dp}\) ,而且还让我们换每个根分别做一次, 然后这样就愉快的 \(\text{TLE}\) 了,所以我们要 ...
- 【iOS开发】创建单例的两种方法
创建一个单例很多办法.我先列举一个苹果官方文档中的写法. [cpp] view plaincopy static AccountManager *DefaultManager = nil; + ( ...
- Java面试题(下)
这部分主要是开源Java EE框架方面的内容,包括hibernate.MyBatis.spring.Spring MVC等,由于Struts 2已经是明日黄花,在这里就不讨论Struts 2的面试题, ...
- struts标签中的select
<!-- Struts下拉列表标签: name="deptId" 下拉列表标签的名称(服务器根据这个名称获取选择的项的实际的值value值) headerKey 默认选择项的 ...
- java解析XML的方法
1.DOM 实现方法 xml文件 <?xml version="1.0" encoding="utf-8"?> <Accounts> & ...
- MongoDB 存储日志数据
MongoDB 存储日志数据 https://www.cnblogs.com/nongchaoer/archive/2017/01/11/6274242.html 线上运行的服务会产生大量的运行及访问 ...
- 【bzoj1951】[Sdoi2010]古代猪文 费马小定理+Lucas定理+中国剩余定理
题目描述 求 $g^{\sum\limits_{k|n}C_{n}^{\frac nk}}\mod 999911659$ 输入 有且仅有一行:两个数N.G,用一个空格分开. 输出 有且仅有一行:一个 ...
- 【bzoj1176】[Balkan2007]Mokia/【bzoj2683】简单题 CDQ分治+树状数组
bzoj1176 题目描述 维护一个W*W的矩阵,初始值均为S(题目描述有误,这里的S没有任何作用!).每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数 ...