TopCoder problem "RaceTrack" used in TCO07 Round 1C (Division I Level Two)



Problem Statement

    

A race track is represented as a line segment. You are given its length, and a int[] pos containing the positions where judges may be located. Each element of pos is the distance from the starting point of the race track. The elements of pos are given in strictly increasing order (pos[i] < pos[i+1]).

You are given an int judges, the number of judges in the next competition. You must assign the judges to positions such that the distance between the two closest judges is as large as possible. Return a String containing exactly n characters, where n is the number of elements in pos. The i-th character should be '1' (one) if there is a judge assigned to the i-th position, and '0' (zero) if there is not. The judges are lazy and don't want to go far from the starting point, so if there are multiple optimal solutions, return the one that comes latest lexicographically.

 

Definition

    
Class:RaceTrack
Method:judgePositions
Parameters:int, int, int[]
Returns:String
Method signature:String judgePositions(int length, int judges, int[] pos)
(be sure your method is public)
    
 

Constraints

-length will be between 1 and 1000000, inclusive.
-pos will contain between 2 and 50 elements, inclusive.
-Each element of pos will be greater than the previous, if it exists.
-Each element of pos will be between 0 and length, inclusive.
-judges will be between 2 and number of elements in pos, inclusive.
 

Examples

0)
    
11
3
{0, 5, 10, 11}
Returns: "1110"
Another solution that maximizes the distance between the two closest judges is "1101", but it is not the lexicographically latest.
1)
    
11
2
{0, 5, 10, 11}
Returns: "1001"
The distance between the two judges should be as large as possible.
2)
    
11
4
{0, 5, 10, 11}
Returns: "1111"
The judges do not have any choice.
3)
    
1000
5
{6, 9, 33, 59, 100, 341, 431, 444, 565, 857}
Returns: "1000010111"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10743&pm=7670

Writer:

Mike Mirzayanov

Testers:

PabloGilberto , brett1479 , vorthys , Olexiy

Problem categories:

Greedy, Search