HDU1798 简单高中的计算几何题= =。正余弦定理的综合应用么。。。
2014-02-07 20:57
344 查看
Tell me the area
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1629 Accepted Submission(s): 490
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 题意:给你两圆坐标和各自的半径,求公共部分面积。 思路:分析两圆关系先:1.外切或相离面积为0 2.内含或内切面积为小圆面积。 3.相交:A.相交弦在圆心之间 B.相交弦在圆心一侧:后面发现算面积的时候不会有影响。 4.一开始没注意的:两圆可能半径为0.....略坑。。。 相交做法:S=S扇形1+S扇形2-S三角形1-S三角形2,具体可以自己画图。。。高中应该做过类似的解析几何题。。。 注意:后面还WA了一次是因为PI的精度不够,后来换上了官方PI的写法A了- -|||。。。 上代码。。。 [code]#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> //#define PI 3.1415926 using namespace std; int main() { double x1,y1,r1; double x2,y2,r2; double dis; double s; double a1,a2; double s1,s2,ss1,ss2; double PI=2*asin(1.0); //printf("%.10lf\n",PI); while(cin>>x1>>y1>>r1) { cin>>x2>>y2>>r2; dis=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); if(dis>=r1+r2||r1==0||r2==0)//两圆外切或相离或有圆的半径为0 s=0; else if(dis<=abs(r1-r2))//两圆内含或者内切 { if(r1>r2) r1=r2; s=PI*r1*r1; } else { a1=acos((dis*dis+r1*r1-r2*r2)/(2*dis*r1));//在圆O1内的圆心角一半 a2=acos((dis*dis+r2*r2-r1*r1)/(2*dis*r2));//在圆O2内的圆心角一半 s1=r1*r1*sin(a1)*cos(a1);//正弦定理(r1*r1*sin2a2)/2的化简 s2=r2*r2*sin(a2)*cos(a2);//同上 ss1=r1*r1*a1;//第一个扇形的面积。 ss2=r2*r2*a2;//第二个扇形的面积 s=ss1+ss2-s1-s2;//两个扇形的面积之和减去两个三角形的面积。 } printf("%.3lf\n",s); } return 0; }
[/code]
相关文章推荐
- HDU 1154 Cutting a Polygon(基础计算几何知识综合应用)
- hdu-1154 Cutting a Polygon(计算几何综合应用,多模板)
- hdu 2108 简单计算几何 判断凹凸
- HDU 1798 Tell me the area(计算几何,求相交圆面积)
- HDU 4720 Naive and Silly Muggles (简单计算几何)
- hdu 4709 Herding (简单计算几何)
- 简单计算几何 hdu-4491 Windmill Animation
- HDU 5533 简单计算几何
- HDU 4643 GSM 简单计算几何 (2013多校联合)
- hdu 4097 简单计算几何
- pick定理的应用——简单的计算几何问题Triangle
- HDU 1077Catching Fish(简单计算几何)
- hdu 4643(简单计算几何)
- HDU 4643 GSM 简单计算几何
- [您有新的未分配科技点]计算几何入门(1):点,向量以及向量的简单应用
- 简单计算几何 hdu-4491 Windmill Animation
- HDU 1077Catching Fish(简单计算几何)
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
- HDU 4617 Weapon (简单三维计算几何,异面直线距离)
- hdu 1245 Saving James Bond 最短路spfa+简单计算几何