fork download
  1. import math
  2.  
  3. def floatRange(start, stop, step):
  4. i = start
  5. while i < stop:
  6. yield i
  7. i += step
  8.  
  9. class Point:
  10. def __init__(self, x=0, y=0):
  11. self.x = x
  12. self.y = y
  13.  
  14. def squareDistTo(self, point):
  15. return (self.x-point.x)**2 + (self.y-point.y)**2
  16.  
  17. class UnitCircle:
  18. def __init__(self, center=Point(0,0)):
  19. self.center = center
  20.  
  21. def __contains__(self, point):
  22. return self.center.squareDistTo(point) < 1.0
  23.  
  24. def overlappingArea(self, other):
  25. if self.center.squareDistTo(other.center) >= 2:
  26. return 0
  27. inSelf = inBoth = 0
  28. for i in floatRange(-1.0, 1.0, 0.002):
  29. for j in floatRange(-1.0, 1.0, 0.002):
  30. p = Point(self.center.x + i, self.center.y + j)
  31. if p in self:
  32. inSelf += 1
  33. if p in other:
  34. inBoth += 1
  35. return math.pi * inBoth / inSelf
  36.  
  37. if __name__ == '__main__':
  38. x, y, u, w = [float(s) for s in raw_input().split()]
  39. a = UnitCircle(Point(x,y))
  40. b = UnitCircle(Point(u,w))
  41. print 2*math.pi - a.overlappingArea(b)
  42.  
Success #stdin #stdout 4.4s 7856KB
stdin
-0.5 0 0.5 0
stdout
5.05485001011