Taxi Cab Scheme
Time limit1sMemory limit128 MB
Given taxi rides sorted by departure time, find the fewest cabs needed so each ride is served, where a cab reaches the next pickup at least one minute early.
Problem
Running a taxi company is not as simple as it may seem. Besides the obvious need to centrally dispatch cabs so that customers calling right now are picked up as quickly as possible, you also have to plan how to assign every ride that has been booked in advance. Given the list of all taxi rides booked for the next day, determine the minimum number of cabs needed to serve all of them.
To keep things simple, we model the city as a rectangular grid. An address is given by two integers: a street number and an avenue number. The time a taxi needs to travel from address to address is minutes. A cab may take a booked ride if either it is the cab's first ride of the day, or the cab can travel from the destination of its previous ride to the source of the new ride and arrive at least one minute before the new ride's scheduled departure. Note that some rides may finish after midnight.
Input
The first line of input contains a single positive integer , the number of scenarios that follow. Each scenario starts with a line containing an integer (), the number of booked taxi rides. The next lines describe the rides. Each ride is given by a departure time in the format hh:mm (from 00:00 to 23:59), two integers for the coordinates of the source address, and two integers for the coordinates of the destination address. All coordinates are at least 0 and strictly less than 200. Within each scenario the booked rides are sorted by increasing departure time.
Output
For each scenario, output one line with the minimum number of cabs required to serve all of the booked taxi rides.