Ural的归类是几何题。简单地说就是有一个边长为L的正方形,中心是一个半径为R的圆的圆心,求圆和正方形的相交面积。
分了三种情况讨论就好了,L / 2 > R, sqrt(2) * L < R, 还有当中的情况。分析仔细之后算就可以了。
#include<stdio.h>
#include<math.h>
const float PI = 3.1415927;
int main() {
float l, r;
scanf("%f %f", &l, &r);
float ret;
if (r * 2 <= l) {
ret = r * r * PI;
} else if (l * l * 2 < 4 * r * r) {
ret = l * l;
} else {
float s1 = acos(l / 2.0 / r) / PI * PI * r * r;
float s2 = sqrt(r * r - l * l / 4.0) * l / 2.0;
ret = PI * r * r - (s1 - s2) * 4;
}
printf("%.3f\n", ret);
return 0;
}