The Climbing Wall
InterviewTime limit2sMemory limit512 MB
Given holds on a wall, find the fewest holds Bessie must step on to climb from within 1000 mm of the ground to within 1000 mm of the top, moving only between holds at most 1000 mm apart.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Shortest path, Geometry
- Solved
- No attempts yet
Problem
The most popular attraction at the county fair is the climbing wall. Bessie wants to plan her route up the wall before she starts.
The wall is 30000 millimeters wide and () millimeters high. It holds () hoof holds, each given as a coordinate in millimeters, and no two holds share a position. The coordinate is the ground at the left edge of the wall. A cow cannot use holds that sit too close together, so the distance between any two holds is at least 300 millimeters. At least one way up exists.
Bessie climbs by stepping on one hold at a time. She can move from one hold to another only when the straight line distance between them is at most 1000 millimeters, and the move may go up, down, right, left, or any mix of those. Once she reaches a hold that is at least millimeters above the ground, she can climb from there onto the platform on top of the wall. She starts on any hold whose coordinate is at most 1000 millimeters.
Given the height of the wall and the positions of the holds, find the smallest number of holds Bessie has to step on to reach the top.
Input
- The first line contains and separated by a space.
- Each of the next lines contains the and coordinates of one hold, separated by a space. is the distance from the left edge of the wall and is the height above the ground, with and .
Output
- Print the smallest number of holds Bessie must step on to reach the top of the wall. The count includes the hold she starts on and the last hold she uses before the platform.