TopcoderArchive
Archive
Algorithm problem

ConnectionPoint

Problem statement, definition, constraints, and public examples.

Problem Statement

You want to estimate the number of cars that are in range of a particular wireless connection point. All cars are described by their distances to the connection point and by their velocities. At time 0 all cars move towards the connection point, though they will all eventually pass and move away from it. Given radius, the maximum possible distance at which a connection is possible, return the maximal possible number of cars that will be in range at once.

Definition

Class:
ConnectionPoint
Method:
maximalConnections
Parameters:
int[], int[], int
Returns:
int
Method signature:
int maximalConnections(int[] position, int[] speed, int radius)
(be sure your method is public)

Notes

  • A device can connect to the connection point if its distance is exactly equal to radius.

Constraints

  • position and speed will contain the same number of elements.
  • position and speed will contain between 0 and 50 elements, inclusive.
  • All elements of position will be between 0 and 1000, inclusive.
  • All elements of speed will be between 1 and 1000, inclusive.
  • radius will be between 1 and 1000, inclusive.

Examples

  1. {100, 20, 50}
    {1, 10, 2}
    10
    Returns: 1
    Car 0 will be in range from time 90 to 110. Car 1 will be in range from time 1 to 3. Car 2 will be in range from time 20 to 30. Clearly, no more than one car will ever be in range.
  2. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3}
    2
    Returns: 6
    The last car goes slightly faster, and will be in range from time 8/3 to 4. At time 3.5, the car that starts 9 units away will have just come into range. The car that started 5 units away will have moved 7 units at time 3.5, and so it will be just on the edge of the range. The cars that started between 5 and 9 units away will all still be in range also, since they move at the same speed. Hence, the 6 cars starting between 5 and 10 units away, inclusive, will all be in range at exactly time 3.5.
  3. {798, 892, 442, 458, 700, 95, 569, 754, 722, 407,
     62, 151, 648, 888, 501, 393, 574, 666, 909, 301,
     637, 36, 746, 256, 7, 265, 853, 536, 720, 856,
     168, 570, 525, 384, 527}
    {451, 846, 677, 768, 767, 661, 737, 720, 548, 658,
     463, 951, 552, 988, 208, 990, 145, 950, 265, 952,
     534, 710, 630, 191, 703, 571, 543, 859, 202, 411,
     869, 615, 576, 251, 654}
    388
    Returns: 26
  4. {50, 50, 50, 50, 50, 50, 50, 50}
    {1, 2, 3, 4, 5, 6, 7, 8}
    1
    Returns: 1
Back to all problems