fork(2) download
  1. def parse(inFile):
  2. return tuple(inFile.getFloats())
  3.  
  4. from math import sqrt, asin, pi
  5.  
  6. def integralOfSqrtOneMinusXSquared(x):
  7. return (sqrt(1 - x * x) * x + asin(x)) / 2
  8.  
  9. def areaOfRectangleInsideUnitCircle(n,n2,x,x2):
  10. # rectangle is [n,x] x [n2,x2]
  11. if (n * n + n2 * n2) >= 1: return 0
  12. if (x * x + x2 * x2) <= 1: return (x2 - n2) * (x - n)
  13. if (n * n + x2 * x2) >= 1:
  14. x2 = sqrt(1 - n * n)
  15. if (n2 * n2 + x * x) >= 1:
  16. x = sqrt(1 - n2 * n2)
  17. if (x * x + x2 * x2) <= 1: return (x2 - n2) * (x - n)
  18. m = sqrt(1-x2*x2)
  19. m2 = sqrt(1 - x * x)
  20. return (m - n) * (x2 - n2) + (m2 - n2) * (x - m) + integralOfSqrtOneMinusXSquared(x) - integralOfSqrtOneMinusXSquared(m) - (x - m) * m2
  21.  
  22. def solve2(r,g):
  23. tot = 2 * r + g
  24. area = 0
  25. i = 0
  26. while (i <= 1 + r):
  27. n = max(i - r, 0)
  28. x = min(i + r, 1)
  29. area += 2 * (integralOfSqrtOneMinusXSquared(x) - integralOfSqrtOneMinusXSquared(n))
  30. j = 0
  31. while (j <= 1 + r):
  32. n2 = max(j - r, 0)
  33. x2 = min(j + r, 1)
  34. area -= areaOfRectangleInsideUnitCircle(n,n2,x,x2)
  35. j += tot
  36. i += tot
  37. return area * 4
  38.  
  39. def solve1(R,t,r,g):
  40. return (((2 * R - t) * t * pi) + solve2(r/(R-t),g/(R-t)) * (R - t) * (R - t)) / (pi * R * R)
  41.  
  42. def solve((f,R,t,r,g)):
  43. if (R - t < f): return 1.0
  44. if (g < 2 * f): return 1.0
  45. return "%.7f" % solve1(R,t+f,r+f,g-2*f)
  46.  
  47. if __name__ == "__main__":
  48. from GCJ import GCJ
  49. GCJ(parse, solve, "/Users/lpebody/gcj/2008_q/", "c").run()
  50.  
  51.  
  52.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty