Advertisement
tadejpetric

Untitled

Jul 26th, 2018
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. import math
  2. from cmath import phase
  3.  
  4. stevilo = int(input())
  5. class strelci():
  6.     def __init__(self, x, y, r):
  7.         self.x = x
  8.         self.y = y
  9.         self.radius = r
  10.         self.kot = []
  11.     def simplify_angle(self):
  12.         i = 0
  13.         j = 0
  14.         dolzina = len(self.kot)
  15.         #print(self.kot, dolzina)
  16.         while i < dolzina:
  17.             while j < dolzina and i < dolzina:
  18.                 if  i != j and self.kot[j][0] >= self.kot[i][0]:
  19.                     if self.kot[j][0] > self.kot[i][1]:
  20.                         #they are not touching
  21.                         j += 1
  22.                         continue
  23.                     if self.kot[j][1] <= self.kot[i][1]:
  24.                         #this means the angle is contained, delete it
  25.                         dolzina -= 1
  26.                         del self.kot[j]
  27.                         i,j = 0,0
  28.                         continue
  29.                     #print(self.kot[i], self.kot[j])
  30.                     self.kot[i][1] = self.kot[j][1]
  31.                     #we extend the first arc, so it's 1st + 2nd
  32.                     dolzina -= 1
  33.                     del self.kot[j]
  34.                     i,j = 0,0
  35.                     #print(self.kot, i, j)
  36.                     continue
  37.                 j += 1
  38.             j = 0
  39.             i += 1
  40.         #print (self.kot)
  41.     def addup(self):
  42.         #print (self.kot)
  43.         probability = 0
  44.         for i in self.kot:
  45.             probability+=i[1]-i[0]
  46.         return 1-probability/(2*math.pi)
  47.  
  48.  
  49. vsi = []
  50. for _ in range(stevilo):
  51.     x,y,r = map(int, input().split())
  52.     vsi.append(strelci(x, y, r))
  53.  
  54. probability = []
  55.  
  56. for i in range(len(vsi)):
  57.     for j in range(len(vsi)):
  58.         if i != j:
  59.             razdalja = math.hypot(vsi[i].x-vsi[j].x, vsi[i].y-vsi[j].y)
  60.             angle = math.asin(vsi[j].radius/razdalja)
  61.             #center_angle = math.asin((vsi[j].y-vsi[i].y)/razdalja)
  62.             center_angle = phase(complex(vsi[j].x-vsi[i].x, vsi[j].y-vsi[i].y))
  63.             if center_angle < 0:
  64.                 center_angle = math.pi-center_angle
  65.             #print (center_angle-angle, center_angle+angle)
  66.             if center_angle-angle > 0:
  67.                 vsi[i].kot.append([center_angle-angle, center_angle+angle])
  68.             else:
  69.                 vsi[i].kot.append([center_angle-angle+2*math.pi, 2*math.pi])
  70.                 vsi[i].kot.append([0, center_angle+angle])
  71.     vsi[i].simplify_angle()
  72.     probability.append(vsi[i].addup())
  73.  
  74. i = 1
  75. for x in probability:
  76.     i*=x
  77. print("%.6f"%round(i,6))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement