TopCoder problem "Warehouse" used in SRM 177 (Division I Level Three)



Problem Statement

    Our warehouse is square, 200 feet on each side, with solid north and south walls. The east and west walls have sliding doors which allow trucks free entry and exit. Trucks come in a variety of sizes, but the width of each truck is an integer number of feet. Unfortunately the roof is supported by posts (of negligible size).

We want to drive big trucks in a straight line into the warehouse through the west wall and (after unloading and without changing direction) out through the east wall. Create a class Warehouse that contains the method feetWide that takes the positions of the posts as inputs and returns the width of the widest truck (of integral width) that can drive straight through without touching any posts (or the north or south wall). The positions of the posts are given by int[] x and int[] y: the i-th element of x and y gives the distance in feet east and north respectively from the southwest corner of the building to the i-th post.

 

Definition

    
Class:Warehouse
Method:feetWide
Parameters:int[], int[]
Returns:int
Method signature:int feetWide(int[] x, int[] y)
(be sure your method is public)
    
 

Constraints

-x has between 1 and 50 elements inclusive
-y has the same number of elements as x
-each element of x and y is between 0 and 200 inclusive
 

Examples

0)
    
{0}
{200}
Returns: 199
The only post is at one of the corners of the building.
1)
    
{100,100,120}
{60,140,180}
Returns: 79
The best path is due east, but the first and second posts are only 80 feet apart so the truck must be less than 80 feet wide.
2)
    
{100,120}
{60,140}
Returns: 82
The best path is a little south of east, going between the two posts. The distance between the posts is sqrt(6800) = 82.xxx

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1140

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4690&pm=1140

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

Geometry