TopCoder problem "UnitsMoving" used in SRM 278 (Division I Level Three)



Problem Statement

    You are to write a procedure for a computer game that will move groups of units.



You are given a String[] start containing the starting positions of all the units. Each element is formatted as "X Y V", where (X, Y) are integer coordinates, and V is an integer velocity in meters per second. You are also given a String[] finish containing the ending positions for all the units. Each element is formatted as "X Y", where (X, Y) are integer coordinates, and each element is distinct from the other elements. The ith element of start represents a single unit which must be moved from the coordinates in start[i] to the coordinates in some element of finish at the velocity given in start[i]. Each unit must be moved to a different location (that means, each two different units from start must be moved to different ending positions). Return a double representing the minimal time (in seconds) in which all the units will reach their destinations.
 

Definition

    
Class:UnitsMoving
Method:bestTime
Parameters:String[], String[]
Returns:double
Method signature:double bestTime(String[] start, String[] finish)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to 1e-9 relative or absolute.
 

Constraints

-start will contain between 1 and 50 elements, inclusive.
-finish will contain the same number of elements as start.
-Each element of start will be formatted as "X Y V", where X, Y and V are integers without leading zeroes.
-Each element of finish will be formatted as "X Y", where X and Y are integers without leading zeroes.
-All X and Y will be between 0 and 1000, inclusive.
-All V will be between 1 and 10, inclusive.
-All elements of finish will be different.
 

Examples

0)
    
{"0 0 1", "0 1 1"}
{"1 1", "1 0"}
Returns: 1.0
The first unit moves to the second location for 1 second, and the second unit moves to the first location also for 1 second.
1)
    
{"0 0 1", "0 1 1"}
{"1 1", "2 1"}
Returns: 2.0
In this case, it is better to move the fist unit to the first location and the second unit - to the second one.
2)
    
{"0 0 1", "5 0 1"}
{"5 12", "10 12"}
Returns: 13.0
3)
    
{"0 0 2", "5 0 1"}
{"5 12", "10 12"}
Returns: 12.0
4)
    
{"308 994 10", "157 22 9", "282 975 5", "993 17 8", "925 771 2", "843 110 6", 
"860 629 8", "947 143 6", "921 348 7", "520 607 6", "735 306 3",
"253 861 7", "562 56 9", "243 168 2", "521 971 1", "745 537 7"}
{"431 911", "109 951", "177 721", "295 831", "937 256", "608 180", "863 994", "148 406",
"275 531", "635 297", "681 404", "909 151", "569 730", "332 391", "94 97", "376 142"}
Returns: 115.72920979597156

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8075&pm=5921

Writer:

Vedensky

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Graph Theory