美丽的花环
1000ms
65536KB
Special Judge
64-bit integer IO format:
%lld Java class name:
Main
Font Size:
学校的草坪上最近种植了一些漂亮的花卉,所有的花围成了一个环形(内径为r,外径为R,0 <r < R) 。原来这片地上有一个用于喷灌的喷头。这个喷头可以为半径K以内的植物提供水。(如图)
现在,HK请你帮忙计算一下,花构成的环形当中有多大面积的可以由喷头提供灌溉。
Input
输入数据只有两行。
格式为(中间使用空格隔开)
x1 y1 R r
x2 y2 K
花环中心在(x1,y1) ,外径为R,内径为r。
喷头的位置为(x2,y2),覆盖范围为K。
其中,x1,y1,R,r,x2,y2,K均为实数。
Output
输出题目描述中所求面积(保留2位小数)。
Sample Input
5 5 20 10 2 2 20
Sample Output
773.09
Hint
π的值请取:3.1415926或acos(-1.0)
Source
Author
huangkun @ bnu
Tags ( Click to see )#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pi acos(-1.0)
double distance(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double area(double x1,double y1,double r1,double x2,double y2,double r2)
{
double d=distance(x1,y1,x2,y2);
if(d>=r1+r2)
return 0;
double max_r,min_r;
max_r=r1>r2?r1:r2;
min_r=r1<r2?r1:r2;
if(d+min_r<=max_r)
return pi*min_r*min_r;
double a=acos((r1*r1+d*d-r2*r2)/2/r1/d);
double b=acos((r2*r2+d*d-r1*r1)/2/r2/d);
double area1=a*r1*r1;
double area2=b*r2*r2;
double areaX=area1+area2;
double ans=sin(a)*r1*d;
areaX-=ans;
return areaX;
}
int main()
{
double x1,y1,R,r,x2,y2,r2;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&R,&r,&x2,&y2,&r2))
{
printf("%.2lf\n",area(x1,y1,R,x2,y2,r2)-area(x1,y1,r,x2,y2,r2));
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pi acos(-1.0)
double distance(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double area(double x1,double y1,double r1,double x2,double y2,double r2)
{
double d=distance(x1,y1,x2,y2);
if(d>=r1+r2)
return 0;
double max_r,min_r;
max_r=r1>r2?r1:r2;
min_r=r1<r2?r1:r2;
if(d+min_r<=max_r)
return pi*min_r*min_r;
double a=acos((r1*r1+d*d-r2*r2)/2/r1/d);
double b=acos((r2*r2+d*d-r1*r1)/2/r2/d);
double area1=a*r1*r1;
double area2=b*r2*r2;
double areaX=area1+area2;
double ans=sin(a)*r1*d;
areaX-=ans;
return areaX;
}
int main()
{
double x1,y1,R,r,x2,y2,r2;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&R,&r,&x2,&y2,&r2))
{
printf("%.2lf\n",area(x1,y1,R,x2,y2,r2)-area(x1,y1,r,x2,y2,r2));
}
return 0;
}