Nhat xet 1: de co res thi 2 trong 3 bien co gia tri bang nhau
Nhat xet 2: x > 2 -> co the tao ra cau hinh(x-2, y+1, z+1), tuong tu y va z
Truong hop cuoi: (a1 < a2 < a3)
Chien thuat: giam so lon nhat
FILENAME = "TACKE"
x,y,z = 0, 0, 0
with open(f"{FILENAME}.INP") as f:
s = f.read()
x,y,z = s.split()
x = int(x)
y = int(y)
z = int(z)
a = [x,y,z]
res = []
def running(a):
if ((a[0] == a[1]) or (a[1] == a[2]) or (a[0] == a[2])):
return False
a = sorted(a)
if ((a[0] + 1 == a[1]) and (a[1] + 1 == a[2])):
return False
else:
return True
while(running(a)):
if (a[0] > a[1] and a[0] > a[2]):
a[0] -= 2
a[1] += 1
a[2] += 1
elif (a[1] > a[0] and a[1] > a[2]):
a[0] += 1
a[1] -= 2
a[2] += 1
else:
a[0] += 1
a[1] += 1
a[2] -= 2
def check(a):
if (a[0] == a[1] or a[1] == a[2] or a[0] == a[2]):
return True
else:
return False
with open(f"{FILENAME}.OUT", 'w') as f:
if (not check(a)):
f.write("KHONG")
else:
a = [x,y,z]
while(not check(a)):
if (a[0] > a[1] and a[0] > a[2]):
if (a[1] > a[2]):
# 0 > 1 > 2
a[0] -= 1
a[1] -= 1
a[2] += 2
res.append(a)
a[0] -= 1
a[1] += 2
a[2] -= 1
res.append(a)
else:
# 0 > 2 > 1
a[0] -= 1
a[2] -= 1
a[1] += 2
res.append(a)
a[0] -= 1
a[2] += 2
a[1] -= 1
res.append(a)
elif (a[1] > a[0] and a[1] > a[2]):
if (a[0] > a[2]):
# 1 > 0 > 2
a[1] -= 1
a[0] -= 1
a[2] += 2
res.append(a.copy())
a[1] -= 1
a[0] += 2
a[2] -= 1
res.append(a.copy())
else:
# 1 > 2 > 0
res.append(a.copy())
a[1] -= 1
a[2] -= 1
a[0] += 2
res.append(a.copy())
a[1] -= 1
a[2] += 2
a[0] -= 1
else:
if (a[0] > a[1]):
# 2 > 0 > 1
res.append(a.copy())
a[2] -= 1
a[0] -= 1
a[1] += 2
res.append(a.copy())
a[2] -= 1
a[0] += 2
a[1] -= 1
else:
# 2 > 1 > 0
res.append(a.copy())
a[2] -= 1
a[1] -= 1
a[0] += 2
res.append(a.copy())
a[2] -= 1
a[1] += 2
a[0] -= 1
if (a[0] == a[1]):
while(a[0] > 0):
a[0] -= 1
a[1] -= 1
a[2] += 2
res.append(a.copy())
elif (a[1] == a[2]):
while(a[1] > 0):
a[2] -= 1
a[1] -= 1
a[0] += 2
res.append(a.copy())
else:
while(a[0] > 0):
a[0] -= 1
a[2] -= 1
a[1] += 2
res.append(a.copy())
#in kq
for a in res:
for i in a:
f.write(f"{i} ")
f.write("\n")