Given n directed rays and two points s and t, find the minimum number of rays a curve from s to t must cross.
Medium7GeometryGraphShortest pathNo attempts yetTime limit2sMemory limit512 MB
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 s and have to run to a point t, and you want the path you run to cross as few beams as possible.
The field is a two dimensional plane. The n opponents o1,o2,…,on stand at n distinct points p1,p2,…,pn, and opponent oi fires a one way beam from pi. Some beams can be parallel. The points s and t differ from every pi.
Your path is any curve from s to t. It crosses a beam when it passes from one side of that beam to the other side. Beam i covers pi and the points after it along the chosen direction, so a path that goes around pi on the side the beam does not cover never crosses beam i.
Find the smallest number of beams a path from s to t has to cross.
The input holds several test cases. The first line of a test case has n, the number of laser beams (1≤n≤200). Each of the next n lines has four space separated integers. The first two are the x and y coordinates of an opponent, and the last two are the x and y coordinates of a point that lies on that opponent's beam. The last line of a test case has four integers, the x and y coordinates of s followed by the x and y coordinates of t.
No three of the points given in a test case lie on one line, and every coordinate has absolute value at most 108. A line holding a single 0 ends the input, and you do not process it.
For each test case, print one line with the minimum number of beams the path has to cross.