Statistics

Problem Statement for "TimerCallback"

Problem Statement

PROBLEM STATEMENT

Many programming libraries support the scheduling of event notification at a
regular interval, often by selecting the initial delay before the first
notification and the the period between notifications.  If the initial delay
was 1000 milliseconds and the period was 200 milliseconds, then notification
would occur at T+1000, T+1200, T+1400, T+1600, ... where T is the time that the
callback is registered.

You are to create a class TimerCallback that contains the method
countCallbacks.  Your method should take a set of callback notification
requests, an inclusive starting time, and an exclusive ending time.  A callback
request will consist of two integer values separated by a single space.  The
first value will be the initial firing time and the second value will be the
period.  If the period is 0 the callback should only be fired once. The method
should return the total number of callbacks that will occur during the interval
between the starting and ending times.

DEFINITION

Class name: TimerCallback
Method name: countCallbacks
Parameters: String[], int, int
Returns: int

Here is the method signature (be sure your method is public): int
countCallbacks(String[] requests, int begin, int end) 

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:

* requests will contain between 0 and 20 elements, inclusive.
* each element of requests will be of the form "<starting time> <period>",
where <starting time> and <period> are ints in the range 0 to 100000,
inclusive, and exactly one space separates the two.
* begin and end will be between 0 and 100000, inclusive.

EXAMPLES

If requests={"100 0", "200 50"}, begin=0, and end=500, then the first request
will trigger a callback at time 100, and the second request will trigger a
callback at times 200, 250, 300, 350, 400, 450, 500, 550, ...  Only the
callback times >= begin and < end should be counted, so 6 callbacks from the
second request fall in the time range.  The return value from the function
should be 7.

If requests={"0 1"}, begin=1000, and end=1500, then the return value should be
500.

If requests={}, begin=1000, and end=0, then the return value should be 0.

If requests={"100 0", "200 10", "10 1000"}, begin=0, and end=10, then the
return value should be 0.

If requests={"100 10", "50 10"}, begin=0, and end=200, then the return value
should be 25.

If requests={"10 0", "10 0"}, begin=10, and end=10, then return value should be
0.

Definition

Class:
TimerCallback
Method:
countCallbacks
Parameters:
String[], int, int
Returns:
int
Method signature:
int countCallbacks(String[] param0, int param1, int param2)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: