1月 20, 2009

【解題】Is This Integration?

@
ACM Volume CII 10209 - Is This Integration?


The Problem

In the image below you can see a square ABCD, where AB = BC = CD = DA = a. Four arcs are drawn taking the four vertexes A, B, C, D as centers and a as the radius. The arc that is drawn taking A as center, starts at neighboring vertex B and ends at neighboring vertex D. All other arcs are drawn in a similar fashion. Regions of three different shapes are created in this fashion. You will have to determine the total area if these different shaped regions.




Input

The input file contains a floating-point number a (0 <= a <= 10000) in each line which indicates the length of one side of the square. Input is terminated by end of file.


Output

For each line of input, output in a single line the total area of the three types of region (filled with different patterns in the image above). These three numbers will of course be floating point numbers with three digits after the decimal point. First number will denote the area of the striped region, the second number will denote the total area of the dotted regions and the third number will denote the area of the rest of the regions.


Sample Input

0.1
0.2
0.3


Sample Output

0.003 0.005 0.002
0.013 0.020 0.007
0.028 0.046 0.016


解題思考

  這題是數學題,求出公式這題就搞定了。雖然如此,這題我還是想了好久。

  其實,只要能畫出那條關鍵的輔助線,這題並沒有那麼難:



  看出來了嗎?


  為了方便起見,我們將黃色區域面積設為 A,綠色區域面積設為 B,藍色區域面積設為 C。

  由於圖中的 BF 線段(即圓半徑)長度為 a,BE 線段長度為 a / 2,我們便可得到:∠BFE = ∠CBF = 30°。於是,我們就可以求出,圖中八分之一的藍色區域面積為:a × (a / 2) - [(a / 2) × (√3 a / 2)] / 2 - a × a × π / 12。

  經過整理,便可得到:C = a × a × [4 - √3 - (2π / 3)]


  接著,由於整個圖形面積為 A + B + C = a × a,又因為圖中的四分之一圓面積為 A + 3B / 4 + C / 2 = a × a × π / 4。經過聯立消去法之後得到:B + 2C = a × a × (4 - π)。

  將 C 帶入上述算式中,便可得到:B = a × a × [-4 - 2√3 + (π / 3)]


  同樣的,把 B 與 C 代入 A + B + C = a × a 中,也可以得出:A = a × a × [1 + (π / 3) - √3]


參考解答(C++)

#include <iostream>
#include <iomanip>
#include <cmath>

#define PI 2.0 * acos(0.0)
#define A(r) (r) * (r) * (1  + PI * 1.0 / 3.0 - sqrt(3))
#define B(r) (r) * (r) * (-4 + PI * 1.0 / 3.0 + sqrt(3) * 2)
#define C(r) (r) * (r) * (4  - PI * 2.0 / 3.0 - sqrt(3))

using namespace std;

int main(void)
{
    double a;

    // 設定顯示至小數點第三位
    cout << setiosflags(ios::fixed) << setprecision(3);

    while (cin >> a)
    {
        cout << A(a) << " " << B(a) << " " << C(a) << endl;
    }

#ifndef ONLINE_JUDGE
    system("pause");
#endif
}

0 回覆:

張貼留言