PythonProject
This commit is contained in:
54
п.py
Normal file
54
п.py
Normal file
@@ -0,0 +1,54 @@
|
||||
f=open('32.txt')
|
||||
f.readline()
|
||||
a1=[]
|
||||
a2=[]
|
||||
a3=[]
|
||||
for s in f.readlines():
|
||||
s = s.replace(',', '.').split()
|
||||
x, y = float(s[0]), float(s[1])
|
||||
if x < 3 and y < 4:
|
||||
a1.append((x, y))
|
||||
else:
|
||||
if x<5 and y>6:
|
||||
a2.append((x, y))
|
||||
else:
|
||||
a3.append((x, y))
|
||||
|
||||
sm1 = sm2 = sm3 = 10**10
|
||||
x1=y1=x2=y2=x3=y3=0
|
||||
for i in range(len(a1)):
|
||||
d_sm = 0
|
||||
for j in range(len(a1)):
|
||||
d_sm += ((a1[j][0] - a1[i][0])**2 + (a1[j][1] - a1[i][1])**2) ** 0.5
|
||||
|
||||
if d_sm < sm1:
|
||||
x1 = a1[i][0]
|
||||
y1 = a1[i][1]
|
||||
sm1 = d_sm
|
||||
|
||||
for i in range(len(a2)):
|
||||
d_sm = 0
|
||||
for j in range(len(a2)):
|
||||
d_sm += ((a2[j][0] - a2[i][0])**2 + (a2[j][1] - a2[i][1])**2) ** 0.5
|
||||
|
||||
if d_sm < sm2:
|
||||
x2 = a2[i][0]
|
||||
y2 = a2[i][1]
|
||||
sm2 = d_sm
|
||||
|
||||
for i in range(len(a3)):
|
||||
d_sm = 0
|
||||
for j in range(len(a3)):
|
||||
d_sm += ((a3[j][0] - a3[i][0])**2 + (a3[j][1] - a3[i][1])**2) ** 0.5
|
||||
|
||||
if d_sm < sm3:
|
||||
x3 = a3[i][0]
|
||||
y3 = a3[i][1]
|
||||
sm3 = d_sm
|
||||
|
||||
|
||||
Px = (x1+x2+x3)/3
|
||||
Py = (y1+y2+y3)/3
|
||||
|
||||
|
||||
print(int(Px*10000), int(Py*10000))
|
||||
Reference in New Issue
Block a user