Preventing Paradoxes
InterviewTime limit1sMemory limit128 MB
Given the vertices of a simple polygon in order, decide whether the traversal orientation is clockwise or counterclockwise.
- Level
Medium4 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
Time traveling runs the risk of causing all sorts of problems and paradoxes—duplicate people, parallel universes, and black holes, to name a few. Tim is well aware of what's at stake, but he keeps time traveling because he knows the secret: you have to properly close the tears in the space-time continuum! You do this simply by visiting each space-time destination in a right-handed (that is, clockwise) orientation.
Tim has a list of points in the space-time plane that describe his trip, and he must start and end at the same point. There are two ways to traverse the list: forwards and backwards. One way leads to prosperity, the other to paradoxes and total ruin. Write a program that, following the points in the given input order, decides whether Tim's right hand would be touching the interior of the polygon.
Input
The first line contains the number of data sets. It is followed by data sets, each of the following form.
The first line of each data set contains the number () of space-time points in Tim's trip. Each of the next lines contains two integers and , a space-time coordinate, where is plotted on the x-axis and on the y-axis, with . Taken in order, the points always form a closed, non-self-intersecting polygon, and no three consecutive points are collinear.
Output
For each data set, first print Data Set x: on a line by itself, where is its number. On the next line, print RIGHT if, looking down on the space-time plane, Tim's right hand would touch the interior of the polygon as he traverses the points in input order; otherwise print LEFT. Separate consecutive data sets with a blank line.