from random import random, randint
N, M = 1000, 30
tasks = [random() for _ in range(N)]
w = sum(tasks)
for i in range(N):
tasks[i] /= w
servers = [0.] * M
for t in tasks:
servers[randint(0, M - 1)] += t
print(min(servers), max(servers))
discount, p = [1., 1.], 1. - 29. / 61.
for dist in range(1, 7):
discount.append(discount[-1] * p)
discount += discount[-2:-8:-1]
res, cnt = 0., 0
for king in range(64):
for rook1 in range(64):
for rook2 in range(64):
if king == rook1 or king == rook2 or rook1 == rook2:
continue
cnt += 1
kingx, kingy = divmod(king, 8)
rook1x, rook1y = divmod(rook1, 8)
rook2x, rook2y = divmod(rook2, 8)
attac1hor = 1. if kingy == rook1y else 0.
attac1ver = 1. if kingx == rook1x else 0.
attac2hor = 1. if kingy == rook2y else 0.
attac2ver = 1. if kingx == rook2x else 0.
if kingx == rook1x == rook2x:
if kingy < rook1y < rook2y or kingy > rook1y > rook2y:
attac2ver = 0.
elif kingy < rook2y < rook1y or kingy > rook2y > rook1y:
attac1ver = 0.
elif kingy == rook1y == rook2y:
if kingx < rook1x < rook2x or kingx > rook1x > rook2x:
attac2hor = 0.
elif kingx < rook2x < rook1x or kingx > rook2x > rook1x:
attac1hor = 0.
attac1 = attac1hor * discount[kingx - rook1x] + attac1ver * discount[kingy - rook1y]
attac2 = attac2hor * discount[kingx - rook2x] + attac2ver * discount[kingy - rook2y]
res += attac1 + attac2 - attac1 * attac2
print(res / cnt * 2.)
0.3756044599826443
from sympy import *
left, right, pln, a = symbols('left right pln a')
left = a
right = -2 * a + 1
pln = left - right
print(pln) # 3*a - 1
print(pln / polys.polytools.LC(pln)) # a - 1/3
print(solvers.solve(pln, a)) # [1/3]
def f()
[1] # или [1, 2], или [1, 2, 3]
end
a, _ = f()
p a # выведет 1 по-любому