天天看點

HDU - 5858 Hard problem (非常詳細的解答)Hard problem

Hard problem

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?

HDU - 5858 Hard problem (非常詳細的解答)Hard problem

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 Outpu

0.29      

題意:

求 兩塊 黑色的陰影面積。

思路:

HDU - 5858 Hard problem (非常詳細的解答)Hard problem

利用數學公式,一步一步化簡。

已知三角形的三邊長度,求面積 。用海倫公式   ==>SA

用餘弦定理 ==> 角a 的度數 da

利用扇形的面積公式 ==>SA_B  , 進而 ==> SB

用餘弦定理和 換角公式 cos(pai - a) = -cosa   ==> B的度數 dB

利用扇形的面積公式 ==>SB_C  ,進而 ==>SC(是 1/4 的陰影面積)

AC代碼:

#include <cstdio>
#include <cmath>

int main()
{
    int T;
    scanf("%d",&T);
    double L;
    double a,b,c,p;
    double SA,SA_B,SB,SB_C,SC;
    double db,cos_a ,dB;
    double ans;
    while(T--){
         scanf("%lf",&L);    // (1 <= L <= 10000)
         a = L;
         b = L/2;
         c = sqrt(2.0)*L/2;

         p = (a+b+c)/2;  //半周長
         SA = sqrt(p*(p-a)*(p-b)*(p-c) );
            //db = acos( (a*a+c*c-b*b)/(2*a*c) );//化簡之後是下面
         db = ( acos( 1.25/sqrt(2.0) ) );
         SA_B = db *a*a/2;
         SB = SA_B - SA;
            //cos_a = b*b+c*c-a*a)/(2*b*c);
            //dB = acos( -cos_a);  //化簡之後是下面
         dB = acos( sqrt(2.0)/4 );
         SB_C = dB *b*b/2;
         SC = SB_C - SB;
         ans = 4*SC; //最終結果

        printf("%.2f\n",ans);
    }
    return 0;
}
           

有不懂的,可以問我!