Laser Game
Time limit2sMemory limit512 MB
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 and have to run to a point , and you want the path you run to cross as few beams as possible.
The field is a two dimensional plane. The opponents stand at distinct points , and opponent fires a one way beam from . Some beams can be parallel. The points and differ from every .
Your path is any curve from to . It crosses a beam when it passes from one side of that beam to the other side. Beam covers and the points after it along the chosen direction, so a path that goes around on the side the beam does not cover never crosses beam .
Find the smallest number of beams a path from to has to cross.
Input
The input holds several test cases. The first line of a test case has , the number of laser beams (). Each of the next lines has four space separated integers. The first two are the and coordinates of an opponent, and the last two are the and coordinates of a point that lies on that opponent's beam. The last line of a test case has four integers, the and coordinates of followed by the and coordinates of .
No three of the points given in a test case lie on one line, and every coordinate has absolute value at most . A line holding a single 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.