ACM--两圆交集的面积--HDOJ 1798--Tell me the area
2016-05-24 16:38
399 查看
HDOJ题目地址:传送门
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2451 Accepted Submission(s): 747
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.
![](http://acm.hdu.edu.cn/data/images/C125_1007_1.jpg)
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
解题思路
高中知识,先判断两个圈的状态(相交,相切,相离)。如果相交,用余弦定理:cosA=(b*b+c*c-a*a)/2*b*b分别求出两个弧的角度,用两个圆弧面积之和剪掉两个三角形面积
参考博客:传送门
Tell me the area
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2451 Accepted Submission(s): 747
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.
![](http://acm.hdu.edu.cn/data/images/C125_1007_1.jpg)
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
解题思路
高中知识,先判断两个圈的状态(相交,相切,相离)。如果相交,用余弦定理:cosA=(b*b+c*c-a*a)/2*b*b分别求出两个弧的角度,用两个圆弧面积之和剪掉两个三角形面积
#include<stdio.h> #include<math.h> #define PI acos(-1.0) int main() { double a1,b1,r1,a2,b2,r2,d; double A1,A2,s1,s2,s; while(scanf("%lf%lf%lf%lf%lf%lf",&a1,&b1,&r1,&a2,&b2,&r2)!=EOF) { d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)); if(d>=r1+r2) printf("0.000\n"); else if(d<=fabs(r1-r2)&&d>=0) { if(r1>r2) printf("%0.3lf\n",PI*r2*r2); else printf("%0.3lf\n",PI*r1*r1); } else { A1=2*acos((d*d+r1*r1-r2*r2)/(2*d*r1));//余弦定理 A2=2*acos((d*d+r2*r2-r1*r1)/(2*d*r2)); s1=0.5*r1*r1*sin(A1)+0.5*r2*r2*sin(A2);//三角形面积 s=a*b*sinC/2; s2=A1/2*r1*r1+A2/2*r2*r2;//圆弧面积 s=A*l*l/2; s=s2-s1; printf("%.03lf\n",s); } } }
参考博客:传送门
相关文章推荐
- JS+Canvas绘制时钟效果
- xlsxwriter使用啊
- 主题样式切换代码:jQuery Theme Switcher
- 低权重网站通过外链获得流量的办法
- 二位数组的排序
- R语言学习之路(一)向量
- WebViewJavascriptBridge工程结构和源码解析
- 页面速度优化个人总结
- linux上安装Eclipse
- 练习 2:高斯分布,正态分布
- java小知识点 2015/10/6
- 操作系统 面试资料
- scala的内部类和外部类
- 小米线刷机教程
- Java网络编程笔记
- java连接连接数据库、分析分析身份证号
- Dex Loader] Unable to execute dex: Multiple dex files define Lde/measite/smack/AndroidDebugger$1;异常处
- 服务器重启后自动登录拉起程序
- 去除inline-block元素间间距,比较靠谱的两种办法
- Winform 绘制圆形的图片