#K96312. Detect Right-Angled Triangle Among Stars
Detect Right-Angled Triangle Among Stars
Detect Right-Angled Triangle Among Stars
In this problem, you are given the coordinates of n stars on a 2D plane. Your task is to determine whether any three of these stars form a right-angled triangle. A triangle is right-angled if the square of one side is equal to the sum of the squares of the other two sides, i.e., it satisfies the Pythagorean theorem:
\(a^2 + b^2 = c^2\)
If such a trio of stars exists, output YES
, otherwise output NO
. The input will be given via standard input and the result must be printed to standard output.
inputFormat
The first line contains an integer n representing the number of stars. The following n lines each contain two integers x and y, which represent the coordinates of a star.
Example:
5 1 1 7 1 1 5 6 10 7 5
outputFormat
Output a single line with YES
if there exists at least one triplet of stars that forms a right-angled triangle. Otherwise, output NO
.
5
1 1
7 1
1 5
6 10
7 5
YES