Health in Hazard
Time limit3.5sMemory limit1024 MB
Given N half-plane cuts through a plane with a den at the origin, find the first cut after which no point on the circle of radius D is reachable.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Sorting
- Solved
- No attempts yet
Problem
In the frozen wilderness, a polar bear lives on a vast glacier, represented as a 2D plane. The bear's den is at . To stay healthy, each time the bear wakes up in its den, it walks to any point at distance exactly from the den. Distance is Euclidean.
Scientists received a report of predictions about how global warming will affect the glacier in the coming days. The predictions are in chronological order. Each one is an infinite line that marks a melting event. Once a prediction comes true, the bear cannot cross its line anymore.
At first the glacier is infinite in all directions, and the bear can roam freely. But the glacier may shrink until the bear can no longer be healthy. Find the earliest moment when no point at distance exactly from the den can be reached by the bear.

The figure shows the first test case. The circle contains the points at distance exactly from the den. With only the first three predictions (solid lines), the bear can still reach points on the circle. Once the fourth prediction (dashed line) is also considered, no point on the circle can be reached from the den.
Input
The first line contains an integer () and a rational number with at most five digits after the decimal point (). is the number of predictions, and is the distance from the den.
Each of the next lines contains four integers , , , and (, and ). They define the infinite line through and . The bear cannot cross this line once the prediction comes true. The predictions are in chronological order and are numbered from 1 to in that order. No line passes through the den.
Output
Output a single line with the number of the earliest prediction after which no point at distance exactly from the den can be reached by the bear. If this never happens, output *. The answer does not change if varies by up to from the given value.