#K41412. Convex Polygon Checker
Convex Polygon Checker
Convex Polygon Checker
Given a set of points that represent the vertices of a polygon in a specific order, determine whether these points form a convex polygon. A polygon is convex if every internal angle is less than or equal to 180° and, equivalently, if every line segment between two vertices remains inside or on the boundary of the polygon. Mathematically, for three consecutive points ( a, b, c ), the sign of the cross product [ \vec{ab} \times \vec{bc} = (b_x - a_x)(c_y - a_y) - (b_y - a_y)(c_x - a_x) ] must remain the same (ignoring zeros) as you traverse the polygon. The input consists of multiple test cases and you must check convexity for each case.
Note: Assume that the points are given in the order of the polygon's vertices.
inputFormat
The input is provided via standard input (stdin). The first line contains an integer ( T ) indicating the number of test cases. For each test case, the first line contains an integer ( N ) which denotes the number of points. The next ( N ) lines each contain two space-separated integers representing the ( x ) and ( y ) coordinates of the points in the order of their appearance in the polygon.
outputFormat
For each test case, output a single line to the standard output (stdout) with the string "YES" if the points form a convex polygon, or "NO" if they do not.## sample
2
4
0 0
0 1
1 1
1 0
5
0 0
1 1
2 0
3 1
4 0
YES
NO
</p>