Running 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 minimise 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.ios
Inputide
On 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.ui
Outputspa
For each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi rides.code
Sample Inputorm
2 2 08:00 10 11 9 16 08:07 9 16 10 11 2 08:00 10 11 9 16 08:06 9 16 10 11
Sample Outputci
1 2
題意:get
有m個任務,每一個任務有開始時間(xx:xx),起點(a,b)與終點(c,d)而後作完這個任務的時間是|a-c|+|b-d|分鐘,若是一個車子在一天(00:00 to 23:59)以內作完i任務以後又能作j任務,那麼這個車子就作2個任務,依次類推下去,問最少須要多少輛車子把全部任務都作完。input
題解:
建圖:i的開始時間+作完i任務的時間+作完i任務的終點到j任務的起點的時間 < j開始的時間
那麼作完i又能作完j,則i指向j,而後求最小路徑覆蓋便可。string
代碼:
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 505; struct Edge{ int to,next; Edge(){} }E[MAXN*MAXN]; int head[MAXN],tot; inline void Add(int from,int to){ E[++tot].next = head[from]; head[from] = tot; E[tot].to = to; } struct V{ int time,x,y,xt,yt; bool operator < (const struct V &b)const { return time < b.time; } }board[MAXN]; int pre[MAXN]; bool used[MAXN]; int Find(int x){ for(int i=head[x] ; i ; i=E[i].next){ if(used[E[i].to])continue; used[E[i].to] = true; if(pre[E[i].to] == 0 || Find(pre[E[i].to])){ pre[E[i].to] = x; return 1; } } return 0; } inline void init(){ memset(head,0,sizeof head); memset(pre,0,sizeof pre); tot = 0; } int main(){ int T,N; scanf("%d",&T); while(T--){ scanf("%d",&N); init(); for(int i=1 ; i<=N ; ++i){ int a,b; scanf("%d:%d",&a,&b); board[i].time = a*60+b; scanf("%d %d %d %d",&board[i].x,&board[i].y,&board[i].xt,&board[i].yt); } sort(board+1,board+1+N); for(int i=1 ; i<=N ; ++i){ for(int j=i+1 ; j<=N ; ++j){ int a = abs(board[i].xt-board[i].x) + abs(board[i].yt-board[i].y); int b = abs(board[j].x-board[i].xt) + abs(board[j].y-board[i].yt); if(a+b<board[j].time-board[i].time)Add(i,j); } } int sum = 0; for(int i=1 ; i<=N ; ++i){ memset(used,false,sizeof used); sum += Find(i); } printf("%d\n",N-sum); } return 0; }