hdu 5858 Hard problem

来源:互联网 发布:微信mac版 dmg 编辑:程序博客网 时间:2024/05/20 23:57

Hard problem

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


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
 

这道题是个数学题,一开始总想着切割算,结果是要加辅助线再利用三角函数。。。。差点就要用积分去算了。将靠近右边与靠近下边的交点分别与左上角顶点相连。

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <vector>#include <cmath>using namespace std;const double N=acos(-1.0);int main(){    double l;    int T;    cin>>T;    while(T--)    {        cin>>l;        double l1,l2,l3,l4;        l1=l*sqrt(2.0)/2;        l2=l;        l3=l/2;        double z,z1;        z=(l2*l2+l1*l1-l3*l3)/(2*l1*l2);        z1=(l1*l1+l3*l3-l2*l2)/(2*l1*l3);        double A,B,C;        A=acos(z);        B=acos(z1);        double s1,s2,s3;        s1=l2*l2*A/2;        s2=l1*l2*(sqrt(1-z*z))/2;        C=N-B;        s3=l3*l3*C/2;        double s;        s=4*(s3-(s1-s2));        printf("%.2f\n",s);    }    return 0;}


原创粉丝点击