Martian Volleyball
Time limit1sMemory limit512 MB
Given an axis-parallel polygon, find the minimum number of points outside the court such that every side has a point on its supporting line.
- Level
Medium6 of 10
- Topics
- Geometry, Graph, Combinatorics, Hash map
- Solved
- No attempts yet
Problem
Volleyball is popular on Mars, just as it is on Earth, and the rules are the same as in terrestrial volleyball: a team must not let the ball touch its own half of the court. One thing is different. A Martian court does not have to be rectangular. Any polygon works as a court as long as every side is parallel to a coordinate axis.
A ball that lands very close to a court line starts an argument, so every Martian volleyball match has line judges. A line judge watches the ball as it lands near a line and calls it in or out.
A line judge can watch a side only while standing on the straight line that contains that side. When the lines of several sides all pass through the spot where a judge stands, that judge watches all of those sides at once, and the sides assigned to one judge may be perpendicular to each other. For safety, the Intergalactic Federation of Martian Volleyball set two rules:
- a judge must stay in place during the match;
- a judge may not stand inside the court, not even on its line.
The figure below shows three possible court shapes with a minimum allocation of judges for each. Court (a) needs four judges, court (b) needs seven judges, and court (c) needs six judges.

Given the shape of the court, write a program that determines the minimum number of line judges needed so that every side of the court is watched by at least one judge.
Input
The input holds several test cases. The first line of a test case has an even integer , the number of sides of the court (). Each of the next lines has two integers and , the coordinates of one vertex of the court (). The coordinates come in order along the court: and form a side of the court for , and forms a side with . Consecutive sides of the court are always perpendicular, and the polygon given in the input is always simple.
The end of the input is a line with . Do not process that line.
Output
For each test case, print one line with one integer, the smallest number of line judges needed.