==============================================================================
CSC 263 Tutorial 8 Winter 2019
==============================================================================
Solve the following problem. Write code if you like.
---------------
Tricky Elevator
---------------
Imagine you are working in a very tall building. One day, when you enter the
elevator, you notice something different: Most of the buttons in the elevator
are gone, with only two left. One button says "Up by U" where U is an integer,
and the other button says "Down by D" where D is another integer. With an
educated mind you guess that "Up by U" means you'll go up by U floors (or not
moving at all if there aren't enough floors above) if you press the button, and
"Down by D" means that you'll go down by D floors (or not moving at all if
there aren't enough floors below). The building has in total N floors. You are
currently at floor X and you want to go to floor Y. Being a CSC263 trained
computer scientist, you immediately take out your laptop to write a program
that can compute the shortest sequence of button pushes that will take you from
floor X to floor Y; or if it is not possible at all, the program will output the
message "TAKE THE STAIRS!"
Input:
The input consists of one line with five numbers separated by space, namely N X
Y U D, where 1 <= X, Y <= N <= 5,000,000 and 0 <= U, D <= 5,000,000. The floor
indices start from 1, e.g., if N = 10, then X and Y will be in [1, 10]. All
numbers are integers. The values of X and Y are always different.
Output:
Print the minimum number of button pushes needed in order to get from floor X
to floor Y; or, if it is impossible to go from floor X to Y, print "TAKE THE
STAIRS!"
Sample test cases:
10 1 10 2 1
Output:
6
Input:
10 2 3 2 2
Output:
TAKE THE STAIRS!
What if we require that you output the sequence of button pushes?