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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章