Skip to content

Commit 3efae47

Browse files
Add files via upload
1 parent cac2611 commit 3efae47

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)