Hard problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 643 Accepted Submission(s): 410
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
Author
BUPT
Source
就变成了求两个圆面积交问题了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
const int M=1e6+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int i,j,k,n,m;
#define pi acos(-1.0)
typedef struct node
{
double x;
double y;
}point;
double AREA(point a, double r1, point b, double r2)
{
double d=sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
if(d>=r1+r2)return 0;
if(r1>r2){
double tmp=r1;
r1=r2;
r2=tmp;
}
if(r2-r1>=d)
return pi*r1*r1;
double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
double kk;
scanf("%lf",&kk);
point a, b;
a.x=kk/2.0, a.y=kk/2.0;
b.x=kk, b.y=0;
double r1=kk/2.0;
double r2=kk;
double res= AREA(a, r1, b, r2);
double ans=(pi*(kk/2.0)*(kk/2.0)-res)*2.0;
printf("%.2f\n",ans);
}
return 0;
}