Goldman SachsOA #29
Do They Belong?
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & Math
Given a triangle formed by three vertices and the points p and q. Return 0 for a degenerate triangle; otherwise return 1, 2, 3, or 4 depending on whether p and q lie inside the triangle or on its boundary.
Input
A single line containing x1 y1 x2 y2 x3 y3 xp yp xq yq in order; all coordinates are integers in 0..2000.
Output
Return 0..4 according to the cases in the statement: 1 = only p is inside/on the boundary, 2 = only q is inside/on the boundary, 3 = both points are, 4 = neither point is.
Example 1
Input:
0 0 4 0 0 4 1 1 4 4
Output:
1
Example 2
Input:
0 0 3 0 0 3 1 1 4 4
Output:
1
Example 3
Input:
0 0 2 2 4 4 1 1 0 0
Output:
0
Editorial
Loading solution…