Created
April 16, 2017 05:50
-
-
Save anuvrat/7c941901a65f56cc6ca7072e6dd8a431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class CollidingCircles(object): | |
def get_expected_value(self, radii, steps_count): | |
return math.pi * self.__get_expected_value_for_step(radii, steps_count) | |
def __get_expected_value_for_step(self, radii_set, step_idx): | |
if step_idx == 0: | |
return sum(radius * radius for radius in radii_set) | |
total_val = 0 | |
count = 0 | |
for i in range(len(radii_set)): | |
for j in range(i + 1, len(radii_set)): | |
new_list = radii_set[:i] + [radii_set[i] + radii_set[j]] + radii_set[i + 1: j] + radii_set[j+1:] | |
total_val += self.__get_expected_value_for_step(new_list, step_idx - 1) | |
count += 1 | |
return total_val * 1.0 / count | |
if __name__ == '__main__': | |
n, k = map(int, input().strip().split(' ')) | |
r = list(map(int, input().strip().split(' '))) | |
print(CollidingCircles().get_expected_value(r, k)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment