Taxi Cab Scheme
Time Limit: 20000/10000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 707 accepted submission (s): 336
Problem descriptionrunning a taxi station is not all that simple. apart from the obvious demand for a centralised coordination of the cabs in order to pick up the customers calling to get a cab as soon as possible, there is also a need to schedule all the taxi rides which have been booked in advance. given a list Of all booked taxi rides for the next day, you want to minimize the number of cabs needed to carry out all of the rides.
For the sake of simplicity, We model a city as a rectangular grid. an address in the city is denoted by two integers: the street and Avenue number. the time needed to get from the address A, B to C, D by taxi is | a-c | + | B-d | minutes. A cab may carry out a booked ride if it is its first ride of the day, or if it can get to the source address of the new ride from its latest, at least one minute before the new ride's scheduled departure. note that some rides may end after midnight.
Inputon the first line of the input is a single positive integer N, telling the number of test scenarios to follow. each scenario begins with a line containing an integer m, 0 <m <500, being the number of booked taxi rides. the following M lines contain the rides. each ride is described by a departure time on the format hh: mm (ranging from 00:00 to 23:59 ), two integers a B that are the coordinates of the source address and two integers c d that are the coordinates of the destination address. all coordinates are at least 0 and strictly smaller than 200. the booked rides in each scenario are sorted in order of increasing departure time.
Outputfor each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi rides.
Sample input2208: 00 10 11 9 1608: 07 9 16 10 11208:00 10 11 9 1608: 06 9 16 10 11
Sample output12 meaning: There are n passengers, the next n rows of each behavior H: m a B c d that is, the departure time of the passenger (departure time from ---), from (, b) This place arrives at (c, d) This place. The road goes through the time of | a-c | + | B-d |. When a passenger is delivered to the destination, if a passenger's destination arrives at B's initial location before B's departure time, the car can also send B's passenger to the destination. The minimum number of vehicles allowed to deliver all passengers to the destination. Train of Thought: Assume that passengers a can also send passengers B to their destination, and draw a directed edge pointing to B from A, then the question will be given a map of points and directed edges, if each passenger uses a different car to deliver, then a total of n two vehicles are required. If there is a directed edge, N-1 is required. Obviously, we need to require the maximum matching. Code:
1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <algorithm> 5 #include <iostream> 6 using namespace std; 7 #define N 550 8 9 vector<int>ve[N];10 int from[N];11 int visited[N];12 struct node{13 int h, m;14 int t;15 int st;16 int a, b, c, d;17 }a[N];18 19 int march(int u){20 int i, v;21 for(i=0;i<ve[u].size();i++){22 v=ve[u][i];23 if(!visited[v]){24 visited[v]=1;25 if(from[v]==-1||march(from[v])){26 from[v]=u;27 return 1;28 }29 }30 }31 return 0;32 }33 main()34 {35 int i, j, k, num;36 int n, t;37 cin>>t;38 while(t--){39 scanf("%d",&n);40 memset(from,-1,sizeof(from));41 for(i=1;i<=n;i++){42 ve[i].clear();43 scanf("%d:%d %d %d %d %d",&a[i].h,&a[i].m,&a[i].a,&a[i].b,&a[i].c,&a[i].d);44 a[i].t=a[i].h*60+a[i].m+abs(a[i].a-a[i].c)+abs(a[i].b-a[i].d);45 a[i].st=a[i].h*60+a[i].m;46 }47 for(i=1;i<=n;i++){48 for(j=1;j<=n;j++){49 if(i!=j&&a[i].t+abs(a[i].c-a[j].a)+abs(a[i].d-a[j].b)<a[j].st){50 ve[i].push_back(j);51 }52 }53 }54 num=0;55 for(i=1;i<=n;i++){56 memset(visited,0,sizeof(visited));57 if(march(i))58 num++;59 }60 printf("%d\n",n-num);61 }62 }