ValetParking
SRM 267 · 2005-10-05 · by dgoodman
Problem Statement
The lot is full when all but one of the squares is occupied. Given the location of the one empty square and the location of the customer's car, we want to know how many times the valet will have to get into a car and drive it before he can maneuver the customer's car to the location (0,0). The valet is not allowed to drive any of the cars out of the lot.
Create a class ValetParking that contains a method minMoves that is given the coordinates (emptyRow and emptyCol) of the one empty square in the full lot, and the coordinates of the customer's car (cusRow and cusCol). The method returns the number of times the valet will have to move a car.
Constraints
- emptyRow, emptyCol, cusRow, and cusCol will be between 0 and 99, inclusive.
- (emptyRow,emptyCol) is not the same position as (cusRow,cusCol).
50 22 0 0 Returns: 0
The customer's car is already at the exit position.
0 0 1 0 Returns: 1
The valet can immediately drive the customer's car to the empty exit position.
0 0 1 1 Returns: 5
One way to do this is: a) drive a car from 1,0 to 0,0 b) drive the customer's car from 1,1 to 1,0 c) drive a car from 0,1 to 1,1 d) drive a car from 0,0 to 0,1 e) drive the customer's car from 1,0 to 0,0
0 9 13 0 Returns: 82
99 98 99 96 Returns: 590
Submissions are judged against all 67 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ValetParking with a public method int minMoves(int emptyRow, int emptyCol, int cusRow, int cusCol) · 67 test cases · 2 s / 256 MB per case