Official
C - Right Triangle Editorial by en_translator
By Pythagorean theorem, the triangle \(ABC\) is a right triangle if and only if:
- \(AB^2+BC^2=CA^2\), \(BC^2+CA^2=AB^2\), or \(CA^2+AB^2=BC^2\).
Thus, it is sufficient to check if any of the three equations holds. \((x_A-x_B)^2+(y_A-y_B)^2\) can be computed as \((x_A-x_B)^2+(y_A-y_B)^2\).
xA, yA = map(int, input().split())
xB, yB = map(int, input().split())
xC, yC = map(int, input().split())
AB2 = (xA - xB) ** 2 + (yA - yB) ** 2
BC2 = (xB - xC) ** 2 + (yB - yC) ** 2
CA2 = (xC - xA) ** 2 + (yC - yA) ** 2
if AB2 + BC2 == CA2 or BC2 + CA2 == AB2 or CA2 + AB2 == BC2:
print("Yes")
else:
print("No")
posted:
last update: