1
2
3 use strict;
4 use warnings;
5
6 my $pi = 4 * atan2(1, 1);
7
8 sub chord
9 {
10 my( $r, $x, $x1 ) = @_;
11
12 my $xh = sqrt( $r * $r - $x * $x );
13 my $x1h = sqrt( $r * $r - $x1 * $x1 );
14
15 my $ta = $x * $xh / 2.0;
16 my $t1a = $x1 * $x1h / 2.0;
17
18 my $ang = atan2( $xh, $x );
19 my $ang1 = atan2( $x1h, $x1 );
20
21 my $angc = $ang - $ang1;
22
23 my $cha = $r * $r * $angc / 2;
24
25 return ( $cha + $t1a - $ta );
26 }
27
28 sub open_chord
29 {
30 my( $r, $strw, $spcw, $x, $x1 ) = @_;
31
32 my $h = sqrt( $r * $r - $x * $x );
33 my $h1 = sqrt( $r * $r - $x1 * $x1 );
34
35 my $area = 0.0;
36 my $strr = $strw * ($x1 - $x);
37 my $left;
38 my $nexty;
39
40 if ( $strw / 2.0 > $h1 ) {
41 $area += ($x1 - $x) * $h1;
42 $left = ($strw / 2.0) - $h1;
43 $nexty = $strw / 2.0 + $spcw;
44 } else {
45 $area += $strr / 2.0;
46
47 my $n = int(($h1 - ($strw / 2.0)) / ($strw + $spcw));
48
49 $area += $n * $strr;
50
51 my $hsf = ($strw / 2.0) + ($n * ($strw + $spcw)) + $spcw;
52
53 if ( $hsf < $h1 ) {
54 $area += ($h1 - $hsf) * ($x1 - $x);
55 $left = $strw - ($h1 - $hsf);
56 $nexty = $hsf + $strw + $spcw;
57 } else {
58 $left = 0.0;
59 $nexty = $hsf;
60 }
61 }
62
63 my $hl = $h - $h1;
64
65 if ($left > $hl) {
66 $left = $hl;
67 }
68
69 $area += chord($r, $h1, $h1 + $left) - ($left * $x);
70
71 my $y = $nexty;
72
73 while ($y < $h) {
74 my $y1 = $y + $strw;
75 if ( $y1 > $h ) { $y1 = $h; }
76
77 $area += chord($r, $y, $y1) - (($y1 - $y) * $x);
78
79 $y = $y1 + $spcw;
80 }
81
82 return $area;
83 }
84
85 sub main
86 {
87 my $n = int(<>);
88
89 for ( my $i = 1; $i <= $n; $i++ ) {
90 my($f, $R, $t, $r, $g) = split(/\s+/, <>);
91
92 my $cr = $R - $t - $f;
93
94 my $area = 0.0;
95 my $strw = 2 * $r + 2 * $f;
96 my $spcw = $g - 2 * $f;
97
98 if ( $spcw < 0.0 ) { $spcw = 0.0; }
99
100 my $x = $strw / 2.0;
101
102 if ( $x > $cr ) { $x = $cr; }
103
104 $area += chord($cr, 0.0, $x);
105
106 while ($x < $cr) {
107 my $x1 = $x + $spcw;
108 if ( $x1 > $cr ) { $x1 = $cr; }
109 $area += open_chord($cr, $strw, $spcw, $x, $x1);
110
111 my $x2 = $x1;
112 if ( $x1 < $cr ) {
113 $x2 = $x1 + $strw;
114 if ( $x2 > $cr ) { $x2 = $cr; }
115 $area += chord($cr, $x1, $x2);
116 }
117
118 $x = $x2;
119 }
120
121 $area = $area * 4.0 + ($pi * $R * $R - $pi * $cr * $cr);
122
123 my $p = $area / ($pi * $R * $R);
124
125 printf "Case #$i: %f\n", $p;
126 }
127 }
128
129 main();