Yoyodyne Propulsion Systems

Three years ago, Yoyodyne Propulsion Systems, Inc., of the planet Tau Ceti Prime, received a generous contract from the Department of Stellar Defense (DoSD) to provide the StarBlazers Forces with their next-generation engines. These engines are primarily to be used for ferrying large cargos of supplies to several outposts in the outer rim. These engines have special properties. First of all, they only have two speeds: zero and really-really- fast. Secondly, they do not require any time to go from one speed to the other; They can instantly go from zero to really-really-fast, and vice-versa. In order to receive continued funding, Yoyodyne must provide the DoSD with a demonstration that they have made significant progress towards developing these engines (It’s always the same old story with government funding, isn’t it?!?!). To do this, the DoSD has set up a series of buoys in a remote part of the galaxy, and tasked Yoyodyne with navigating each sequence of buoys given a certain amount of fuel at the start of each sequence. The engines would keep traveling until the last bouy is reached or it runs out of fuel, whichever occurs first. We would assume that the fuel consumtion is uniform throughout the travel. Assume that each mission starts at location (0,0,1). At the start of each mission, and as each buoy is reached, the next buoy to visit is determined by the closest buoy in the mission that has not yet been visited. In case of a tie, the buoy information that comes first in the input is given preference. Your job is to write a program to check if the current prototype engines can successfully complete each mission, given certain mission parameters, and provide some statistics about engine performance. Input The input to this problem consists of maximum 10 missions. The first line of each mission consists four of integers. The first integer, f (1 ≤ f ≤ 20, 000), is the amount of fuel (in kernels) in the tanks at the start of the mission, the next number, b (1 ≤ b ≤ 100) is the burn-rate of the fuel in kernels per second, the third number, r (1 ≤ r ≤ 200) defines how fast really-really-fast is for this mission, in lightyears per second and the fourth integer n (1 ≤ n ≤ 20) denotes the number of buoys in the mission. Each of the next n lines contains three integers x,y,z (−2000 ≤ x, y, z ≤ 2000) defining the (x, y, z) coordinates, in lightyears, of one buoys in this mission. The coordinates can range from -2000 to 2000 inclusive. If two buoys have the same coordinate they should be considered as two different buoys, although the distance between them is zero. The end of input is signified by a line where f = b = r = n = 0. Output You are to output one line for each mission. The output line begins with the word ‘Mission’ followed by a space, the mission number, a colon, and a space. If the mission can be completed, you are to output the word ‘SUCCESS!!’, followed by a space, the word ‘Time:’, a space, the total amount of time to complete the mission, in seconds, followed by two spaces, the word ‘Traveled:’, a space, the total distance traveled for this mission, in lightyears, followed by two spaces, the words ‘Fuel Left:’, a space, and the amount of fuel left in the tanks, in kernels. If the mission cannot be completed, you are to output the word ‘FAILURE!!’, followed by a space, the word ‘Traveled:’, a space, the total distance traveled for this mission, in lightyears, followed by two spaces, the words ‘From Home:’, a space, the distance from the current location to the final buoy, in lightyears, assuming you would traverse all remaining legs of the mission. All numbers in the output (Except the serial of mission) should be rounded to two digits after the decimal point.

2/2 Sample Input 3112 002 003 1112 002 003 200 1 200 4 2000 0 0 -2000 0 0 -2000 0 0 -2000 -2000 -2000 0000 Sample Output Mission 1: SUCCESS!! Time: 2.00~ Traveled: 2.00~ Fuel Left: 1.00 Mission 2: FAILURE!! Traveled: 1.00~ From Home: 1.00 Mission 3: SUCCESS!! Time: 44.14~ Traveled: 8828.43~ Fuel Left: 155.86