Problem Description
cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?
Give you the side length of the square L, you need to calculate the shaded area in the picture.
The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.
Give you the side length of the square L, you need to calculate the shaded area in the picture.
The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.
Input
The first line contains a integer T(1<=T<=10000), means the number of the test case. Each case contains one line with integer l(1<=l<=10000).
Output
For each test case, print one line, the shade area in the picture. The answer is round to two digit.
Sample Input
1 1
Sample Output
0.29
似乎是从中间切开两边用积分求一下。。具体的我不太会推
另外还可以用各种软件直接弄出来
#include <stdio.h>
#include <math.h>
struct point{
double x,y;
};
double distance(point p1,point p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double area_of_overlap(point c1, double r1, point c2, double r2){
double a = distance(c1, c2), b = r1, c = r2;
double cta1 = acos((a * a + b * b - c * c) / 2 / (a * b)),
cta2 = acos((a * a + c * c - b * b) / 2 / (a * c));
double s1 = r1*r1*cta1 - r1*r1*sin(cta1)*(a * a + b * b - c * c) / 2 / (a * b);
double s2 = r2*r2*cta2 - r2*r2*sin(cta2)*(a * a + c * c - b * b) / 2 / (a * c);
return s1+s2;
}
int main(void){
int t;
int n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
point a,b;
a.x = 0.5*n;
a.y = 0.5*n;
b.x = 0;
b.y = 0;
double ans = area_of_overlap(a,0.5*n,b,n);
printf("%.2f\n",2*(0.5*n*0.5*n*acos(-1) - ans));
}
return 0;
}