Under construction

Still being built. Things may change

Martian Volleyball

Time limit1sMemory limit512 MB

Summary
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.

Three possible court shapes with a minimum allocation of 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 NN, the number of sides of the court (4≤N≤1004 \le N \le 100). Each of the next NN lines has two integers XiX_i and YiY_i, the coordinates of one vertex of the court (−109≤Xi,Yi≤109-10^9 \le X_i, Y_i \le 10^9). The coordinates come in order along the court: (Xi,Yi)(X_i, Y_i) and (Xi+1,Yi+1)(X_{i+1}, Y_{i+1}) form a side of the court for 1≤i<N1 \le i < N, and (XN,YN)(X_N, Y_N) forms a side with (X1,Y1)(X_1, Y_1). 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 N=0N = 0. Do not process that line.

Output

For each test case, print one line with one integer, the smallest number of line judges needed.

Examples2

  1. Example 1

    Input
    4
    0 0
    9 0
    9 18
    0 18
    8
    0 0
    0 1
    1 1
    1 -1
    -2 -1
    -2 1
    -1 1
    -1 0
    12
    1 0
    2 0
    2 1
    3 1
    3 2
    2 2
    2 3
    1 3
    1 2
    0 2
    0 1
    1 1
    0
    
    Expected output
    4
    7
    6
    
  2. Example 2

    Input
    4
    0 0
    1 0
    1 1
    0 1
    6
    0 0
    4 0
    4 2
    2 2
    2 5
    0 5
    8
    0 0
    3 0
    3 1
    2 1
    2 2
    1 2
    1 3
    0 3
    0
    
    Expected output
    4
    5
    6