решение пункта B
#27 B
f = open('27_B_28766.txt')
cl1 = []
cl2 = []
cl3 = []
for s in f:
x, y, z = s.split()
x = float(x.replace(',', '.'))
y = float(y.replace(',', '.'))
c, size= z[0], z[2:]
if y > 22:
cl1.append((x, y, c, size))
if 15 < y < 22:
cl2.append((x, y, c, size))
if y < 15:
cl3.append((x, y, c, size))
def c(cl):
x_c, y_c, mn = 0, 0, 10**10
for i in range(len(cl)):
res = 0
x1, y1 = cl[i][0], cl[i][1]
for j in range(len(cl)):
x2, y2 = cl[j][0], cl[j][1]
res += ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
if res < mn:
mn = res
x_c, y_c = x1, y1
return x_c, y_c
mncl1 = 10**10
for i in range(len(cl1)):
if cl1[i][2] == 'Z' and cl1[i][3] == 'I':
x1, y1 = cl1[i][0], cl1[i][1]
for j in range(len(cl1)):
if cl1[j][2] == 'Z' and cl1[j][3] == 'I':
x2, y2 = cl1[j][0], cl1[j][1]
res = ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
if res < mncl1 and res != 0:
mncl1 = res
mncl2 = 10**10
for i in range(len(cl2)):
if cl2[i][2] == 'Z' and cl2[i][3] == 'I':
x1, y1 = cl2[i][0], cl2[i][1]
for j in range(len(cl2)):
if cl2[j][2] == 'Z' and cl2[j][3] == 'I':
x2, y2 = cl2[j][0], cl2[j][1]
res = ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
if res < mncl2 and res != 0:
mncl2 = res
mncl3 = 10**10
for i in range(len(cl3)):
if cl3[i][2] == 'Z' and cl3[i][3] == 'I':
x1, y1 = cl3[i][0], cl3[i][1]
for j in range(len(cl3)):
if cl3[j][2] == 'Z' and cl3[j][3] == 'I':
x2, y2 = cl3[j][0], cl3[j][1]
res = ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
if res < mncl3 and res != 0:
mncl3 = res
print('B1', int(min(mncl1, mncl2, mncl3) * 10_000))
svrgcl1 = 0
for q in cl1:
if q[2] == 'Z' and q[3] == 'I':
svrgcl1 += 1
svrgcl2 = 0
for q in cl2:
if q[2] == 'Z' and q[3] == 'I':
svrgcl2 += 1
svrgcl3 = 0
for q in cl3:
if q[2] == 'Z' and q[3] == 'I':
svrgcl3 += 1
#print(svrgcl1, svrgcl2, svrgcl3) min - cl2 - 1, max - cl3 - 9
x1, y1 = c(cl2)
x2, y2 = c(cl3)
print('B2', int ((((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5) * 10_000))