-
Notifications
You must be signed in to change notification settings - Fork 2
/
problem_Erdash.py
90 lines (65 loc) · 1.92 KB
/
problem_Erdash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
sz = 18
points = 3
def print_matrix(m):
for i in range(sz):
for j in range(sz):
print m[i * sz + j],
print ""
def calc_sizes(x,y,z):
[ix, jx] = divmod(x, sz)
[iy, jy] = divmod(y, sz)
[iz, jz] = divmod(z, sz)
ret = {}
det = {}
det[x] = {}
det[x][y] = pow((pow(ix-iy,2)+pow(jx-jy,2)), 0.5)
det[x][z] = pow((pow(ix-iz,2)+pow(jx-jz,2)), 0.5)
if det[x][y] not in ret:
ret[det[x][y]] = 0
ret[det[x][y]] += 1
if det[x][z] not in ret:
ret[det[x][z]] = 0
ret[det[x][z]] += 1
det[y] = {}
# det[y][x] = pow((pow(iy-ix,2)+pow(jy-jx,2)), 0.5)
det[y][z] = pow((pow(iy-iz,2)+pow(jy-jz,2)), 0.5)
if det[y][z] not in ret:
ret[det[y][z]] = 0
ret[det[y][z]] += 1
# det[z] = {}
# det[z][x] = pow((pow(iz-ix,2)+pow(jz-jx,2)), 0.5)
# det[z][y] = pow((pow(iz-iy,2)+pow(jz-jy,2)), 0.5)
# print "det[{0},{1}][{2},{3}] = {4}".format(ix,jx, iy,jy, det[x][y])
# print "det[{0},{1}][{2},{3}] = {4}".format(ix,jx, iz,jz, det[x][z])
# print "det[{0},{1}][{2},{3}] = {4}".format(iy,jy, iz,jz, det[y][z])
# raw_input()
maximum = [0,0]
for l in ret:
if maximum[0] < ret[l]:
maximum = [ret[l], l]
return maximum
mtrx = {}
mx = 0
mx_matrx = {}
for i in range(sz*sz):
mtrx[i] = 0
for i1 in range(sz*sz): # p1
mtrx[i1] = 1
for i2 in range(i1+1, sz * sz): # p2
mtrx[i2] = 2
for i3 in range(i2+1, sz * sz): # p3
mtrx[i3] = 3
# print_matrix(mtrx)
cur_sizes = calc_sizes(i1,i2,i3)
if mx < cur_sizes[0]:
mx = cur_sizes
mx_matrx = mtrx.copy()
# print "xxxxxxxxxx\nmaximum = {0}".format(mx)
# print_matrix(mx_matrx)
# raw_input()
mtrx[i3] = 0
mtrx[i2] = 0
mtrx[i1] = 0
print "xxxxxxxxxx"
print mx
print_matrix(mx_matrx)