#C10271. Valid Triangle Formation
Valid Triangle Formation
Valid Triangle Formation
You are given n points in the 2D plane. Your task is to determine if there exists a set of three distinct points that form a valid (non-collinear) triangle. A triangle is considered valid if its area is non-zero. You can use the formula for the area of a triangle given by three points \( (x_1, y_1) \), \( (x_2, y_2) \), \( (x_3, y_3) \):
\( Area = \frac{1}{2} \left|x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2)\right| \)If the computed area is zero, then the points are collinear and do not form a valid triangle. Otherwise, they do. Print YES
if such a triangle exists, and NO
if it does not.
inputFormat
The input is read from the standard input (stdin) and has the following format:
\n- \n
- The first line contains an integer \( n \) (\( n \geq 1 \)) representing the number of points. \n
- The following \( n \) lines each contain two integers \( x \) and \( y \), representing the coordinates of each point. \n
outputFormat
Output a single line to the standard output (stdout) containing YES
if any three points form a valid triangle, otherwise output NO
.
4
0 0
1 0
0 1
1 1
YES