2013-10-06 21:06:28Morris

[UVA][math] 10287 - Gifts in a Hexagonal Box

Problem E

Gifts in a Hexagonal Box

Input: standard input

Output: standard output

Time Limit: 2 seconds

Memory Limit: 32 MB

 

When we buy gifts for someone, we also try to make sure that the box in which the gifts are placed is also beautiful. So the gift box is a very important thing. I don’t want to discuss more on this issue, so now let’s move our attention to the image below. This image shows how round gifts can be put optimally in a regular hexagon shaped box (A regular hexagon is a hexagon whose all edges are equal and all internal angles are also equal).

 

 

Given the length of one side of the hexagonal box, you will have to find the radius of the circular gifts for all four cases. You can assume that the placement of the gifts is symmetric as they are shown in the figure above. To be more precise

a)      In the first case the gift touches all six sides of the box.

b)      In the second case both the gifts touch two sides of the box.

c)      In the third case all the gifts touch two different sides of the box.

d)      In the fourth case two gifts touch two different sides of the box and other two touches one side.

e)      The radiuses of all circular gifts are equal for every single case.

Input

The input file contains several lines of input. Each line contains a single non negative floating point number S (S<=10000), here S is the length of one side of the hexagonal box.

 

Output

For each line of input produce one line of output. This line should contain four floating point numbers r1, r2, r3, r4 separated by a single space. Here r1 is the radius of the gift when only one gift is kept inside the box; r2 is the radius of the gifts when only two gifts are placed inside the box. r3 and r4 has similar meanings. The floating point numbers should have ten digits after the decimal point. Outputs will be checked with special judge, so small precision errors will be ignored.

 

Sample Input

0.0000001

0.0000002

0.0000003

 

Sample Output

0.0000000866 0.0000000464 0.0000000433 0.0000000375

0.0000001732 0.0000000928 0.0000000866 0.0000000750

0.0000002598 0.0000001392 0.0000001299 0.0000001125


題目解法:

r1 比較好求得,直接算六邊形的高 /2 即可。
r2 稍微困難一點,兩個圓卡的角,畫出三角形,斜邊+半徑+半徑+斜邊 = 六邊形對角線
r3
比較好求得,直接算六邊形的高 /4 即可。
r4 又稍微困難一點了,這四個圓心連線,恰好是一個菱形。

對於這個菱形的邊為 2*r4。

藉由求 r2 的思路,來求菱形的其中一條對角線 2*S-(4/sqrt(3))*r4。

另一條對角線 sqrt(3)*S - 2*r4。

解畢氏定理得 r4。


#include <stdio.h>
#include <math.h>

int main() {
    double S;
    while(scanf("%lf", &S) == 1) {
        double r1, r2, r3, r4;
        r1 = S*sqrt(3)/2;
        r2 = S/(1+sqrt(12)/3);
        r3 = r1/2;
        double a, b, c;//ax^2 + bx + c = 0
        a = 5.0/3.0;
        b = (sqrt(3)*7.0/3)*S;
        c = -(S*S*(7.0/4));
        r4 = (-b+sqrt(b*b-4*a*c))/a/2;
        printf("%.10lf %.10lf %.10lf %.10lf\n", r1, r2, r3, r4);
    }
    return 0;
}