Ribbon Road
Time limit1sMemory limit1024 MB
Given a simple polygon, Christie's position on its boundary, and a point her ray passes through, decide whether she is inside, outside, or cannot tell.
- Level
Medium6 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
Christie is an ant that likes to crawl on a closed ribbon (a polygon whose start and end points are attached to each other). Her owner, Cindy, places a sugar cube on the ribbon for her to enjoy. Cindy always puts the sugar cube on the exterior side of the ribbon, so Christie wants to crawl on the exterior side to find a sugar cube somewhere down the ribbon road. However, Christie is so tiny that she often cannot tell whether she is crawling on the inside or the outside. If she is on the inside, she has to carefully crawl to the outside.
Christie's antenna emits a signal, which is a ray. A ray travels from her location to some other point , and it may pass through the ribbon. The rays she emits span relative to the line segment she stands on. The direction parallel to that segment and pointing forward is , and the direction parallel to it and pointing away from her is . The span of the ray goes above her.
The ribbon does not twist (it does not rotate about itself), so it is not a Möbius band. Therefore, whether Christie is on the inside or the outside stays the same as she walks along the ribbon.
If the ray is parallel to the segment she stands on, she cannot tell whether she is inside or outside. If she stands on a vertex, she might not be able to tell either. At a vertex, she can be parallel to either edge adjacent to that vertex. Help Christie find out whether she is on the inside of the ribbon road.

An illustration of Christie's antenna range. If the antenna points at or , Christie cannot tell whether she is inside or outside.
Input
The first line contains a single integer (), the number of vertices of the polygon. The next lines each contain a pair of integers , the th vertex of the polygon in order (). The ribbon road is a closed simple polygon, so the last vertex connects back to the first vertex. No three consecutive vertices are collinear.
The final line contains four integers: , Christie's location, and , a point that Christie's signal passes through. Christie always stays on the ribbon in a direction parallel to the ribbon, but has no restrictions. If Christie stands on a vertex, she can be parallel to either edge adjacent to that vertex. It is guaranteed that .
All coordinates satisfy .
Output
Output a single line: inside if Christie is inside the ribbon road, outside if she is outside it, or ? if it cannot be determined.