HDU - 5858(几何计算)
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.
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
求阴影部分面积。
高数学得好的话可以用微积分。。。没错,我暂时还不会。。。
我还是拿出kuangbin模版,求出两个圆相交的面积S,然后用小圆的面积减去S就是一半的阴影部分,再乘以2就是结果。
#include<set> #include<map> #include<stack> #include<queue> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #define mem(a,b) memset(a,b,sizeof(a)) #define maxn 100005 #define maxm 100005 #define mod 1000000007 #define ll long long #define inf 0x3f3f3f3f using namespace std; const double eps=1e-18; const double PI=acos(-1.0); struct p{ double x,y; p(){} p(double _x,double _y){x=_x;y=_y;} p operator -(const p &b)const{ return p(x-b.x,y-b.y); } double operator *(const p &b)const{ return x*b.x + y*b.y; } }; double dist(p a,p b){ return sqrt((a-b)*(a-b)); } double A(p c1,double r1,p c2,double r2){ double d=dist(c1,c2); if(r1+r2<d+eps)return 0; if(d<fabs(r1-r2)+eps){ double r=min(r1,r2); return PI*r*r; } double x=(d*d+r1*r1-r2*r2)/(2.0*d); double t1=acos(x/r1); double t2=acos((d-x)/r2); return r1*r1*t1+r2*r2*t2-d*r1*sin(t1); } int main(){ int t; scanf("%d",&t); while(t--){ double l;scanf("%lf",&l); p p1,p2;p1.x=0,p1.y=l; p2.x=l/2,p2.y=l/2; double ans=((PI*l/2*l/2)-A(p1,l,p2,l/2))*2.0; printf("%.2lf\n",ans); } }