This page is still under construction.

Parts of this page are still being built. What you see may change.

Laser Game

Time limit2sMemory limit512 MB

Summary
Given n directed rays and two points s and t, find the minimum number of rays a curve from s to t must cross.
Level

Medium7 of 10

Topics
Geometry, Graph, Shortest path
Solved
No attempts yet

Problem

You are playing a game against several classmates. Each opponent carries a device that fires one laser beam. The beam starts at that opponent's own position, goes in the direction the opponent picks, and continues forever. Once every beam is aimed and fixed, your turn starts. You stand at a point ss and have to run to a point tt, and you want the path you run to cross as few beams as possible.

The field is a two dimensional plane. The nn opponents o1,o2,…,ono_1, o_2, \dots, o_n stand at nn distinct points p1,p2,…,pnp_1, p_2, \dots, p_n, and opponent oio_i fires a one way beam from pip_i. Some beams can be parallel. The points ss and tt differ from every pip_i.

Your path is any curve from ss to tt. It crosses a beam when it passes from one side of that beam to the other side. Beam ii covers pip_i and the points after it along the chosen direction, so a path that goes around pip_i on the side the beam does not cover never crosses beam ii.

Find the smallest number of beams a path from ss to tt has to cross.

Input

The input holds several test cases. The first line of a test case has nn, the number of laser beams (1≤n≤2001 \le n \le 200). Each of the next nn lines has four space separated integers. The first two are the xx and yy coordinates of an opponent, and the last two are the xx and yy coordinates of a point that lies on that opponent's beam. The last line of a test case has four integers, the xx and yy coordinates of ss followed by the xx and yy coordinates of tt.

No three of the points given in a test case lie on one line, and every coordinate has absolute value at most 10810^8. A line holding a single 00 ends the input, and you do not process it.

Output

For each test case, print one line with the minimum number of beams the path has to cross.

Examples2

  1. Example 1

    Input
    2
    -1 -1 1 1
    -1 1 1 -1
    0 2 0 -2
    6
    -2 0 20 0
    -2 3 20 3
    6 1 -10 1
    5 -5 5 20
    1 -2 7 4
    4 5 -4 -3
    4 4 3 -2
    3
    -4 0 -3 0
    -4 1 -3 1
    0 -5 0 -4
    -1 -1 1 2
    0
    
    Expected output
    0
    2
    1
    
  2. Example 2

    Input
    2
    -5 -4 -4 -3
    5 -4 4 -3
    0 6 0 -9
    0
    
    Expected output
    1