杭电 hdu 1350 和 1960 Taxi Cab Scheme (二分匹配 + 最小路径覆盖)

杭电  hdu  1350  和   1960   Taxi Cab Scheme   (二分匹配  + 最小路径覆盖)



Taxi Cab Scheme

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


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
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:   1054  1179  1528  1287  1498 
 






题意:这里是一个出租车公司,他们会接很多订单,面对订单,他们考虑派多少车去完成,他们的要求是尽量少的派车出去,要是有派出去的车能过完成第n单订单的时候,
还能及时的感到第n+1单订单的地点,就让他接着完成。否则让其他车尝试,或者派新车。
首先是输入T,表示有多少案例
接着是n,表示有多少单的订单
接着是一个00:00这样模式的时间,表示这个订单要这个时间到达目的地
后面是a,b,c,d,分别表示两个地点a,b,表示出发地,c,d表示目的地
然后告诉你路程的时间计算是 |a - c| + |b - d|单位是分钟
问出租车公司最少要派多少辆车才能准时完成所有订单



题解:这是一道还是能看出来的二分匹配的最小路径覆盖,构造边的时候,将能接下去完成的订单之间连接起来,接着就是基础代码


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>

using namespace std;

const int maxn = 505;

int n, m;
bool map[maxn][maxn];                     //记录哪些订单是可以连接下去,也就是时间允许
bool vis[maxn];
int pri[maxn];                          //pri[i] = x,用来判断最后i被x选中,-1则表示没有被选中

struct node                      //记录每一单订单的消息
{
    int time;
    int a, b, c, d;
}cab[maxn];

bool find (int x)
{
    int i;

    for (i = 1; i <= n; i++)
    {
        if (map[x][i] && !vis[i])            //查询可以连续完成的订单,并且是从上到下的遍历
        {
            vis[i] = true;
            if (pri[i] == -1 || find(pri[i]))       //查看是否之前就被选走,要是被选走了,就查看选走的是否有另外的选项
            {
                pri[i] = x;
                return true;
            }
        }
    }
    return false;
}

int main ()
{
    int T, i, j, a, b;

    scanf ("%d", &T);
    while (T--)
    {
       scanf ("%d", &n);
       memset (map, 0, sizeof (map));
       memset (pri, -1, sizeof (pri));
       for (i = 1; i <= n; ++i)
       {
           scanf ("%d:%d %d%d%d%d", &a, &b, &cab[i].a, &cab[i].b, &cab[i].c, &cab[i].d);       //记录每个订单的信息
           cab[i].time = a * 60 + b;
       }
       for (i = 1; i < n; ++i)
       {
           for (j = i + 1; j <= n; ++j)
           {
               if (cab[j].time > (cab[i].time + abs(cab[i].a - cab[i].c) + abs(cab[i].b - cab[i].d) + abs(cab[i].c - cab[j].a) + abs(cab[i].d - cab[j].b)))
                   map[i][j] = 1;                 //遍历,选择可以连续完成到订单之间进行连线
           }
       }
       int ant = 0;
       for (i = 1; i <= n; ++i)
       {
           memset (vis, false, sizeof (vis));
           if (find(i))
               ant++;
       }
       printf ("%d\n", n - ant);
    }

    return 0;
}


Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值