|
| 1 | +There is a wall in your backyard. It is so long that you can�t see its endpoints. |
| 2 | +You want to build a fence of length L such that the area enclosed between the wall and the fence is maximized. |
| 3 | +The fence can be of arbitrary shape, but only its two endpoints may touch the wall. |
| 4 | + |
| 5 | +---------------------------------------------- |
| 6 | + |
| 7 | +Okay, if there is a figure that has a maximum area with a certain perimeter, |
| 8 | + |
| 9 | +1. It must be convex, or we can reflect about a line crossing the boundary and get a greater area. |
| 10 | +2. It must be symmetric or else, we can simply reflect the greater half and geta greater area with the same circumference. |
| 11 | + |
| 12 | +This is repeating Steiner's argument for the isoperimetric theorem (not completely rigorous). |
| 13 | + |
| 14 | +Basically, the curve which maximises area with a fixed perimeter is a circle. |
| 15 | + |
| 16 | +in this question, we must have two endpoints of this curve on a straight line. Therefore, the best answer is a semi-circle. |
| 17 | + |
| 18 | +C = PI r, is given. |
| 19 | + |
| 20 | +Area = half( PI. r^2 ) = half(PI (C/PI) )^2 = C^2/2PI |
| 21 | + |
| 22 | +Make Circumference a double to avoid floating point precision loss. |
| 23 | + |
| 24 | +-------------------------------------------------------------- |
| 25 | + |
| 26 | +void semi_circle_area(double circumference) |
| 27 | +{ |
| 28 | + const double PI = 3.1415926; |
| 29 | + |
| 30 | + double area = (circumference*circumference)/(2*PI); |
| 31 | + printf("%.2lf\n", area); |
| 32 | +} |
| 33 | + |
| 34 | +int main() |
| 35 | +{ |
| 36 | + while(true) |
| 37 | + { |
| 38 | + double circumference; |
| 39 | + scanf("%lf", &circumference); |
| 40 | + |
| 41 | + if(circumference == 0) break; |
| 42 | + |
| 43 | + semi_circle_area(circumference); |
| 44 | + } |
| 45 | + |
| 46 | + return 0; |
| 47 | +} |
0 commit comments