Hdu 1350 Taxi Cab Scheme【最小路径覆盖】

Taxi Cab Scheme

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1149    Accepted Submission(s): 586


Problem 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
 

Source

题目大意:

一共有N个顾客,给出每个顾客的起始位子和目标位子,以及他需要服务的时间。

如果我们一台车将顾客送到了一个目的地之后,再转向其他目的地并且能够在其需要服务的时间前一分钟赶到,那么他就可以接下一位顾客。

问现在最少需要多少车能够使得所有顾客都及时的接受服务。


思路:


1、很经典的最小路径覆盖模型。


2、我们对应按照题意将二分图建好之后跑匈牙利算法即可。

最小路径覆盖数==n-最大匹配数。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std;
const double eps=1e-7;
struct node
{
    int time1,time2;
    int sx,sy;
    int ex,ey;
    int use;
}a[50450];
int match[50000];
int vis[5050];
vector<int >mp[50000];
int abs(int t)
{
    if(t<0)return -t;
    else return t;
}
int find(int u)
{
    for(int i=0;i<mp[u].size();i++)
    {
        int v=mp[u][i];
        if(vis[v]==0)
        {
            vis[v]=1;
            if(match[v]==-1||find(match[v]))
            {
                match[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        memset(match,-1,sizeof(match));
        for(int i=0;i<n;i++)mp[i].clear();
        for(int i=0;i<n;i++)
        {
            scanf("%d:%d%d%d%d%d",&a[i].time1,&a[i].time2,&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
            a[i].use=abs(a[i].sx-a[i].ex)+abs(a[i].sy-a[i].ey);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                int has;
                if(i==j)continue;
                if(a[j].time1*60+a[j].time2>a[i].time1*60+a[i].time2)has=a[j].time1*60+a[j].time2-(a[i].time1*60+a[i].time2);
                else continue;
                int dis=abs(a[j].sx-a[i].ex)+abs(a[j].sy-a[i].ey);
                if(a[i].use+dis<=has-1)
                {
                    mp[i].push_back(j);
                }
            }
        }
        int output=0;
        for(int i=0;i<n;i++)
        {
            memset(vis,0,sizeof(vis));
            if(find(i))output++;
        }
        printf("%d\n",n-output);
    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值