- 0of 0 votes
* Build Offices- keviIma December 26, 2018 in United States
A company wants to develop an office park in an area that has been divided up into a grid where each cell represents a potential building lot. The goal is for the furthest of all lots to be as near as 1 possible to an office building. Determine the building placement to minimize the distance the 0 most distant lot is from an office building. Movement is restricted to horizontal and vertical, i.e. diagonal movement is not allowed.
For example, there are n = 3 office buildings to build on a grid that is w = 4 lots wide and h = 4 lots high. An optimal grid placement sets any lot within two units distance of an office building. In the distance grid below, offices are cells at distance 0.
1 0 1 2
2 1 2 1
1 0 1 0
2 1 2 1
That represents one optimal solution among several, this array rotated for example.
The function must return an integer that denotes the maximal value among shortest distances to the closest office for each cell.
findMinDistance has the following parameter(s): w: an integer, the width of the grid h: an integer, the height of the grid n: an integer, the number of buildings to place
wxh <= 28
| Report Duplicate | Flag | PURGE
Open Chat in New Window