Hill Walk
Time limit1sMemory limit128 MB
Given non-crossing slanted segments, simulate Bessie climbing each hill and falling straight down at its upper end, counting the distinct hills she touches.
- Level
Hard8 of 10
- Topics
- Sorting, Binary search, Geometry, Simulation
- Solved
- No attempts yet
Problem
There are hills (). Each hill is a line segment from to with and . No two segments intersect or even touch, not even at their endpoints, and the first hill satisfies .
Bessie the cow starts at on the first hill. Whenever Bessie is on a hill, she climbs up until she reaches its upper end, then jumps off the edge. If she lands on another hill she keeps walking along that hill; otherwise she falls forever and lands safely on a cushion of pillows at .
Treat each hill from to as containing the point but not the point : if Bessie falls straight down at she lands on the hill, but if she falls at she does not.
Count the total number of hills Bessie touches at some point during her walk.
Input
- Line : the number of hills, .
- Lines : line contains four integers describing hill . Every integer is in the range .
Output
- Line : the number of hills Bessie touches during her journey.
Hint
In the example, there are four hills. The first hill runs from to . Starting on it, Bessie walks along hills #1, #4, and finally #3, touching three hills in total.