Space Bowling
Time limit2sMemory limit1024 MB
Given a triangular array of n rows of circular pins and a ball moving in a straight line, count how many pins the ball touches.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Implementation, Binary search
- Solved
- No attempts yet
Problem
A new space bowling alley has opened on the planet Plyuk. The field of the bowling alley is an infinite plane on which pins are placed.
Each pin is a tall cylinder whose base is a circle of radius meters. All pins are identical. The pins are placed according to the following rules. The pins form rows: the first row holds one pin, the second holds two, and so on. The last, -th row holds pins. Introduce a coordinate system on the plane so that the unit of length equals one kilometer. The center of the only pin in the first row is at . The centers of the pins in the second row are at and . Thus the centers of the pins in the -th row are at the points with coordinates , , , .
The game proceeds as follows. A ball of radius meters is used. The player chooses the initial position of the ball's center and the ball's direction vector . The ball is then placed at the initial position and moves without stopping in the direction of the vector . The ball is considered to have knocked down a pin if at some moment during the ball's motion the ball and the pin share a point. Knocked-down pins do not change the ball's direction and do not knock down neighboring pins as they fall.
The figure shows an example of a pin arrangement for , and a ball for , , , , .

Write a program that, given the pin radius , the number of pin rows , the ball radius , its initial position , and its direction vector , determines the number of pins knocked down by the ball.
Input
The first line of the input file contains two integers and , separated by exactly one space (, ).
The second line of the input file contains an integer ().
The third line of the input file contains two integers and , separated by exactly one space (, , ).
The fourth line of the input file contains two integers and , separated by exactly one space (, ).
Output
The output file must contain a single integer: the number of pins knocked down.
Notes
The figure below shows which pins are knocked down (such pins are marked with «х»).
