def parse(inFile):
return tuple(inFile.getFloats())
from math import sqrt, asin, pi
def integralOfSqrtOneMinusXSquared(x):
return (sqrt(1 - x * x) * x + asin(x)) / 2
def areaOfRectangleInsideUnitCircle(n,n2,x,x2):
# rectangle is [n,x] x [n2,x2]
if (n * n + n2 * n2) >= 1: return 0
if (x * x + x2 * x2) <= 1: return (x2 - n2) * (x - n)
if (n * n + x2 * x2) >= 1:
x2 = sqrt(1 - n * n)
if (n2 * n2 + x * x) >= 1:
x = sqrt(1 - n2 * n2)
if (x * x + x2 * x2) <= 1: return (x2 - n2) * (x - n)
m = sqrt(1-x2*x2)
m2 = sqrt(1 - x * x)
return (m - n) * (x2 - n2) + (m2 - n2) * (x - m) + integralOfSqrtOneMinusXSquared(x) - integralOfSqrtOneMinusXSquared(m) - (x - m) * m2
def solve2(r,g):
tot = 2 * r + g
area = 0
i = 0
while (i <= 1 + r):
n = max(i - r, 0)
x = min(i + r, 1)
area += 2 * (integralOfSqrtOneMinusXSquared(x) - integralOfSqrtOneMinusXSquared(n))
j = 0
while (j <= 1 + r):
n2 = max(j - r, 0)
x2 = min(j + r, 1)
area -= areaOfRectangleInsideUnitCircle(n,n2,x,x2)
j += tot
i += tot
return area * 4
def solve1(R,t,r,g):
return (((2 * R - t) * t * pi) + solve2(r/(R-t),g/(R-t)) * (R - t) * (R - t)) / (pi * R * R)
def solve((f,R,t,r,g)):
if (R - t < f): return 1.0
if (g < 2 * f): return 1.0
return "%.7f" % solve1(R,t+f,r+f,g-2*f)
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2008_q/", "c").run()
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICByZXR1cm4gdHVwbGUoaW5GaWxlLmdldEZsb2F0cygpKQoKZnJvbSBtYXRoIGltcG9ydCBzcXJ0LCBhc2luLCBwaQoKZGVmIGludGVncmFsT2ZTcXJ0T25lTWludXNYU3F1YXJlZCh4KToKICAgIHJldHVybiAoc3FydCgxIC0geCAqIH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ogICAgICAgICAgICBuMiA9IG1heChqIC0gciwgMCkKICAgICAgICAgICAgeDIgPSBtaW4oaiArIHIsIDEpCiAgICAgICAgICAgIGFyZWEgLT0gYXJlYU9mUmVjdGFuZ2xlSW5zaWRlVW5pdENpcmNsZShuLG4yLHgseDIpCiAgICAgICAgICAgIGogKz0gdG90CiAgICAgICAgaSArPSB0b3QKICAgIHJldHVybiBhcmVhICogNAoKZGVmIHNvbHZlMShSLHQscixnKToKICAgIHJldHVybiAoKCgyICogUiAtIHQpICogdCAqIHBpKSAgKyBzb2x2ZTIoci8oUi10KSxnLyhSLXQpKSAqIChSIC0gdCkgKiAoUiAtIHQpKSAvIChwaSAqIFIgKiBSKQoKZGVmIHNvbHZlKChmLFIsdCxyLGcpKToKICAgIGlmIChSIC0gdCA8IGYpOiByZXR1cm4gMS4wCiAgICBpZiAoZyA8IDIgKiBmKTogcmV0dXJuIDEuMAogICAgcmV0dXJuICIlLjdmIiAlIHNvbHZlMShSLHQrZixyK2YsZy0yKmYpCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgZnJvbSBHQ0ogaW1wb3J0IEdDSgogICAgR0NKKHBhcnNlLCBzb2x2ZSwgIi9Vc2Vycy9scGVib2R5L2djai8yMDA4X3EvIiwgImMiKS5ydW4oKQoKICAgICAgICAgICAgCg==