zoj 1597 Circular Area

扇形面积=R*R*Hudu(扇形弧度)/2;

弧长L=R*Hudu(扇形弧度)

 

/*
* zoj1597.c
*
* Created on: 2011-9-21
* Author: bjfuwangzhu
*/

#include<stdio.h>
#include<math.h>
#define pi acos(-1.0)
#define eps 1.0e-8
double distance(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
double x1, y1, r1, x2, y2, r2, r12, dis, temp, res;
while (~scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2)) {
dis = distance(x1, y1, x2, y2);
r12 = fabs(r1 - r2);
if (dis - r1 - r2 > eps) {
printf("%.3lf\n", 0.0);
continue;
}
if (dis - r12 > eps) {
temp = acos((dis * dis + r1 * r1 - r2 * r2) / (2 * dis * r1)) * 2;
res = r1 * r1 * temp / 2.0 - r1 * r1 * sin(temp) / 2.0;

temp = acos((dis * dis + r2 * r2 - r1 * r1) / (2 * dis * r2)) * 2;
res += r2 * r2 * temp / 2.0 - r2 * r2 * sin(temp) / 2.0;
printf("%.3lf\n", res);
continue;
}
temp = r1 > r2 ? r2 : r1;
printf("%.3lf\n", pi * temp * temp);
}
return 0;
}

你可能感兴趣的:(ZOJ)