Description:
The taxi company receives n (n <500) orders. Each order is described as follows: at t time, the [x, y] coordinates must be taken from the [Tx, Ty] coordinates. The time required for taxi driving is | X-TX | + | Y-ty |. Taxi companies want to dispatch the minimum number of vehicles to complete all orders. Send a taxi to pick up any order. If a taxi completes an order, it can arrive at the departure location before the next order time, then it can continue to take the next order. The minimum number of taxis required.
Analysis:
Use an order as a node with a directed acyclic graph. If order I can arrive at order J after it is completed, the directed edge is connected between directed graph I and J. Then find the Directed GraphMinimum path Overwrite.
The minimum path overwrite problem can be convertedBipartite Graph maximum matchingProblem: If node I connects to node J with a connected edge, I connects to node J on the left of the diagram. (In fact, it is the original directed graph, which is converted to a bipartite graph.) The minimum number of path overwrites = number of nodes N-the maximum number of matches.
About this questionNote:It is not only the end of the previous vertex that is equal to the start point of the next vertex that can be connected, as long as a taxi can drive to the next start point in the previous destination can also be connected.
- /*
- Pku2060 taxi cab Scheme
- */
- # Include <stdio. h>
- # Include <memory. h>
- # Define CLR (a) memset (A, 0, sizeof ())
- # Define ABS (A) (a)> 0? (A):-())
- # Define n 1005
- Typedef struct {
- Int H, M;
- } Time;
- Typedef struct {
- Int X, Y, TX, Ty;
- } Ride;
- Int find (int I, int M, int G [] [N], int mat [], int tmat []) {
- Int V, J;
- For (j = 0; j <m; j ++) if (G [I] [J] & tmat [J] = 0 ){
- Tmat [J] = 1; V = mat [J]; MAT [J] = I;
- If (V =-1 | find (v, M, G, mat, tmat) return 1;
- Mat [J] = V;
- }
- Return 0;
- }
- Int match (int g [] [N], int N, int M, int mat []) {
- Int I, j, v, k = 0;
- Int tmat [N];
- For (I = 0; I <m; I ++) mat [I] =-1;
- For (I = 0; I <n; I ++) {CLR (tmat); k + = find (I, m, G, mat, tmat );}
- Return K;
- }
- // Minimum path Overwrite
- Int pathcover (int g [] [N], int N ){
- Int mat [N];
- Return N-match (G, N, N, mat );
- }
- Int dist (int x, int y, int Tx, int ty ){
- Return ABS (X-TX) + ABS (Y-ty );
- }
- Int early (time A, ride P, time B, ride q ){
- Int Dist = 0;
- Dist + = Dist (p. x, p. y, p. tx, p. ty );
- Dist + = Dist (p. tx, p. ty, q. x, q. y );
- A. m + = dist;
- A. h + = a. m/60;
- A. m % = 60;
- If (a. h <B. h) return 1;
- If (a. h> B. h) return 0;
- If (a. m <B. m) return 1;
- Return 0;
- }
- Time t [N];
- Ride r [N];
- Int a [N] [N];
- Int main ()
- {
- Int I, j, k;
- Int T;
- Int n;
- Scanf ("% d", & T );
- While (t --){
- // Input
- Scanf ("% d", & N );
- For (k = 0; k <n; k ++ ){
- Scanf ("% d: % d", & T [K]. H, & T [K]. m );
- Scanf ("% d", & R [K]. x, & R [K]. y, & R [K]. TX, & R [K]. ty );
- }
- // Create Map
- CLR ();
- For (I = 0; I <n; I ++)
- For (j = I + 1; j <n; j ++)
- If (early (T [I], R [I], t [J], R [J])
- A [I] [J] = 1;
- // Output
- Printf ("% d/N", pathcover (A, n ));
- }
- Return 0;
- }