POJ 2060 最小覆蓋路徑

Taxi Cab Scheme
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 6283   Accepted: 2643

Description

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.

Input

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.

Output

For each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi rides.

Sample Input

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 Output

1
2


不錯的最小覆蓋路徑入門題  

題意:出租車公司有訂單,訂單時間,訂單開始XY 訂單結束XY  

行駛時間是曼哈頓路徑

如果第一單跑完後能在第二單預定前1分鐘到達目的地的話。那麼跑第一單的出租車可以繼續跑第二單

問有多少出租車才能跑完所有單


1.一個單獨的頂點是一條路徑;
2.如果存在一路徑p1,p2,......pk,其中p1 爲起點,pk爲終點,那麼在覆蓋圖中,頂點p1,p2,......pk不再與其它的頂點之間存在有向邊.
對於一個路徑覆蓋,有如下性質:
1、每個頂點屬於且只屬於一個路徑。
2、路徑上除終點外,從每個頂點出發只有一條邊指向路徑上的另一頂點。
路徑覆蓋與二分圖匹配的關係(必須是有向無環圖):
最小路徑覆蓋=|P|-最大匹配數
 
於是就得到了最小路徑覆蓋的代碼
#include<stdio.h>  
#include<string.h>  
#include<stdlib.h>

struct Orzpoint{
	int st,et;
	int sx,sy;
	int ex,ey;
	
};
int n,m;  
bool imap[555][555],d[555];  
int s[555];  
bool findOrz(int k){  
    int i;  
    for(i=0;i<n;i++){  
        if(!d[i]&&imap[k][i]){  
            d[i]=1;  
            if(s[i]==-1||findOrz(s[i])){  
                s[i]=k;  
                return true;  
            }  
        }  
    }  
    return false;  
}  
  
int main(){  
    int i,j,k,l,t1,t2,t,orz;  
    int a,b,c,dd,e,f,g;
    Orzpoint point[555];
    scanf("%d",&t);
    while(t--){
    	scanf("%d",&n);
    	memset(s,-1,sizeof(s));
    	memset(imap,0,sizeof(imap));
    	for(i=0;i<n;i++){
	    	scanf("%d:%d%d%d%d%d",&a,&b,&point[i].sx,&point[i].sy,&point[i].ex,&point[i].ey);
	    	point[i].st=a*60+b;
	    	point[i].et=abs(point[i].sx-point[i].ex)+abs(point[i].sy-point[i].ey)+point[i].st;
	    }

		    for(i=0;i<n;i++){
    		for(j=0;j<n;j++){
		    	if(point[i].et+1+abs(point[i].ex-point[j].sx)+abs(point[i].ey-point[j].sy)<=point[j].st){
	    			imap[i][j]=1;
	    		}
		    }
    	}
    	int ans=0;
    	for(i=0;i<n;i++){
	    	memset(d,0,sizeof(d));
	    	if(findOrz(i)){
	    		ans++;
	    	}
	    }
	    
	    printf("%d\n",n-ans);
	    
    }
      
      
}  





發佈了80 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章