hdu 5858 Hard problem(2016 Multi-University Training Contest 10——数学题)

来源:互联网 发布:cx one4.41软件 编辑:程序博客网 时间:2024/05/21 08:38

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5858

Hard problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 253    Accepted Submission(s): 193


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.
 

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
11
 

Sample Output
0.29
 

Author
BUPT
 

Source
2016 Multi-University Training Contest 10
 
题目大意:求阴影部分的面积。

解题思路:将问题转化成两个圆的相交的面积,再用内切圆的面积减去相交面积*2即可。


详见代码。

#include <bits/stdc++.h>using namespace std;#define MAX(x,y) ((x)>(y)?(x):(y))#define MIN(x,y) ((x)<(y)?(x):(y))#define ABS(x)   ((x)>0?(x):(-(x)))#define ll long long#define N 250const int mod=1e9+7;const int inf=99999999;const double esp=1e-9;const double PI=acos(-1.0);/*int main(){    double a1,b1,r1,a2,b2,r2,d;    double A1,A2,s1,s2,s;    while(~scanf("%lf%lf%lf%lf%lf%lf",&a1,&b1,&r1,&a2,&b2,&r2))    {        d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)); //求圆心距        if(d>=r1+r2)            printf("0.000\n");     //两圆相离或相外切        else if(d<=fabs(r1-r2))//内切或内含        {            if(r1>r2)                printf("%0.3lf\n",PI*r2*r2);            else                printf("%0.3lf\n",PI*r1*r1);        }        else        {            A1=2*acos((d*d+r1*r1-r2*r2)/(2*d*r1)); //用余弦定理求以圆心为顶点与两圆交点连线的角            A2=2*acos((d*d+r2*r2-r1*r1)/(2*d*r2));            s1=0.5*r1*r1*sin(A1)+0.5*r2*r2*sin(A2);            s2=A1/2*r1*r1+A2/2*r2*r2;            s=s2-s1;            printf("%0.3lf\n",s);        }    }}*/int main(){    int t;    double R,rr;    double a1,b1,r1,a2,b2,r2,d;    double A1,A2,s1,s2,s;    scanf("%d",&t);    while(t--)    {        scanf("%lf",&R);        rr=R/2;        a1=0,b1=R,r1=R;        a2=rr,b2=rr,r2=rr;        double ans;        d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)); //求圆心距        A1=2*acos((d*d+r1*r1-r2*r2)/(2*d*r1)); //用余弦定理求以圆心为顶点与两圆交点连线的角        A2=2*acos((d*d+r2*r2-r1*r1)/(2*d*r2));        s1=0.5*r1*r1*sin(A1)+0.5*r2*r2*sin(A2);        s2=A1/2*r1*r1+A2/2*r2*r2;        s=s2-s1;        ans=s;        double s1=R*R;        double s2=PI*rr*rr;        ans=(s2-ans)*2;        printf("%.2lf\n",ans);    }    return 0;}


0 0