Rock Climbing
Time limit2sMemory limit512 MB
Given n anchor points and a four-limb climbing model with pairwise distance and height limits, find the fewest moves to touch location n.
- Level
Medium6 of 10
- Topics
- BFS, Graph, Simulation, Geometry
- Solved
- No attempts yet
Problem
A climbing wall, natural or man made, has small holes and protrusions where you can put your fingers or your toes. Reaching a target spot takes planning as much as strength, because before each move you have to know that some limb can go somewhere useful for the step after it.
This problem models that planning as follows. You are given locations on a two dimensional wall. One location takes one hand or one foot. In one move you put exactly one limb on another location, and these rules hold at every moment:
- your two hands are at most units apart, and your two feet are at most units apart;
- your left hand and your left foot are at most units apart, and your right hand and your right foot are at most units apart;
- your left hand and your right foot are at most units apart, and your right hand and your left foot are at most units apart;
- no two limbs are on the same location;
- neither foot is higher than either hand, that is, the coordinate of each foot is at most the coordinate of each hand.
You start with your left foot on location , your right foot on location , your left hand on location , and your right hand on location . The starting position always obeys the rules. You have climbed the wall once any limb is on location . Find the smallest number of moves that puts a limb on location .
Input
The first line contains an integer with , the number of data sets. data sets follow, each in this form.
The first line of a data set contains one integer with , the number of locations. The next line contains real numbers , , , , ..., , , where is the position of location .
Output
For each data set, first print "Data Set x:" on a line of its own, where x is the number of the data set counted from . On the next line print the minimum number of moves until a limb first touches location . If no sequence of moves puts a limb on location , print Impossible on that line instead. Print a blank line after each data set.