http://poj.org/problem?id=3216

Repairing Company
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 6776   Accepted: 1822

Description

Lily runs a repairing company that services the Q blocks in the city. One day the company receives M repair tasks, the ith of which occurs in block pi, has a deadline ti on any repairman’s arrival, which is also its starting time, and takes a single repairman di time to finish. Repairmen work alone on all tasks and must finish one task before moving on to another. With a map of the city in hand, Lily want to know the minimum number of repairmen that have to be assign to this day’s tasks.

Input

The input contains multiple test cases. Each test case begins with a line containing Q and M (0 < Q ≤ 20, 0 < M ≤ 200). Then follow Q lines each with Q integers, which represent a Q × Q matrix Δ = {δij}, where δij means a bidirectional road connects the ith and the jth blocks and requires δij time to go from one end to another. If δij = −1, such a road does not exist. The matrix is symmetric and all its diagonal elements are zeroes. Right below the matrix are M lines describing the repairing tasks. The ith of these lines contains piti and di. Two zeroes on a separate line come after the last test case.

Output

For each test case output one line containing the minimum number of repairmen that have to be assigned.

Sample Input

1 2
0
1 1 10
1 5 10
0 0

Sample Output

2

题目大意:Lily管理q个地方(q*q的矩阵,maps[i][j]表示地点i到j花费的时间),她接到m个任务

每个任务i,该任务的执行的地点为pi,执行人员到达花费时间ti(也是该任务i开始的时间),完成该任务

花费时间di,执行人员完成了上一个任务下能去做下一个任务(即执行人员要想做第j个任务,他完成上一

个任务i花的所有时间+到达第j个任务发生的地点所花的时间<=第j个任务开始的时间);求最少需要多少

执行人员去执行这m个任务

用Floyd来找到地点i到地点j花费的最少时间即最短路(即可以缩短执行人员从i地到j地在路上的时间)

然后用二分匹配,注意二分图的X集合和Y集合都是任务的编号,而不是任务执行的地点如果第i个任务完成

后还能做第j个任务,则i与j之间有一条连线G[i][j] = 1

接下来就是二分匹配的最小覆盖路经问题了
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define N 310
#define INF 0x3f3f3f3f using namespace std; struct node
{
int p, t, d;
}node[N]; int G[N][N], maps[][], vis[N], used[N];
int m, q; bool Find(int u)
{
int i;
for(i = ; i <= m ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} void Floyd()
{
int i, j, k;
for(k = ; k <= q ; k++)
{
for(i = ; i <= q ; i++)
{
for(j = ; j <= q ; j++)
{
if(maps[i][k] + maps[k][j] < maps[i][j])
maps[i][j] = maps[i][k] + maps[k][j];
}
}
}
} int main()
{
int i, j;
while(scanf("%d%d", &q, &m), q + m)
{
memset(G, , sizeof(G));
for(i = ; i <= q ; i++)
{
for(j = ; j <= q ; j++)
{
scanf("%d", &maps[i][j]);
if(maps[i][j] == -)
maps[i][j] = INF;
}
}
for(i = ; i <= m ; i++)
scanf("%d%d%d", &node[i].p, &node[i].t, &node[i].d);
Floyd();
for(i = ; i <= m ; i++)
{
for(j = ; j <= m ; j++)
{
if(i == j)continue;
if(node[i].d + maps[node[i].p][node[j].p] + node[i].t <= node[j].t)
G[i][j] = ;//****注意此处二分图的两个集合元素是任务的编号而不是地点block
}
}
int ans = ;
memset(used, , sizeof(used));
for(i = ; i <= m ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", m - ans);
}
return ;
}
 

poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)的更多相关文章

  1. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  2. poj 3216 Repairing Company

    http://poj.org/problem?id=3216 n个地点,m个任务 每个任务有工作地点,开始时间,持续时间 最少派多少人可以完成所有的任务 传递闭包之后最小路径覆盖 #include&l ...

  3. POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)

    <题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...

  4. POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9794   Accepted: 3 ...

  5. HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)

    题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...

  6. Treasure Exploration---poj2594(传递闭包Floyd+最小路径覆盖)

    题目链接:http://poj.org/problem?id=2594 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过(这就是和单 ...

  7. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  8. hdu 4606 简单计算几何+floyd+最小路径覆盖

    思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...

  9. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

随机推荐

  1. 浅谈配置chrome浏览器允许跨域操作的方法

    浅谈配置chrome浏览器允许跨域操作的方法 一:(Lying人生感悟.可忽略) 最近有一天,对着镜子,发现满脸疲惫.脸色蜡黄.头发蓬松.眼神空洞,于是痛诉着说生活的不如意,工作没激情,工资不高,一个 ...

  2. Home Server

    今天分享一个作品--HomeServer,一个基于云存储理念的集家庭数据存储.共享.管理及远程访问为一体的家用存储设备.通俗的讲,就是一个家庭数据银行,为家庭的数据提供专业.安全.便捷.持久.全天候的 ...

  3. POJ 3468 A Simple Problem with Integers

    线段树的指针表示法. 代码还有待消化.. 代码里面多次用到了函数递归,感觉这次对递归又有了深一层的理解. #define LOCAL #include <iostream> #includ ...

  4. (六) 6.1 Neurons Networks Representation

    面对复杂的非线性可分的样本是,使用浅层分类器如Logistic等需要对样本进行复杂的映射,使得样本在映射后的空间是线性可分的,但在原始空间,分类边界可能是复杂的曲线.比如下图的样本只是在2维情形下的示 ...

  5. MySQL server has gone away 的解决方法

    原文引用至:http://www.jb51.net/article/23781.htm,感谢! 可能原因:1.发送的SQL语句太长,以致超过了max_allowed_packet的大小,如果是这种原因 ...

  6. StringUtils判断字符串是否为空的方法

    public static boolean isEmpty(String str)   判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0   下面是 Stri ...

  7. Android fragment源码全解析

    Fragment 相信基本上每个android developer都用过,但是知晓其原理 用的好的还是不多,今天就从源码的角度上来带着大家分析一下Fragment的源码,对fragment有了更深层次 ...

  8. Arduino 软重启 软件reset

    将12脚连接一个1K电阻,然后用电阻另一端连接RESET脚.注意不是12脚直接连接RESET!! 代码如下(要注意RESET脚为LOW时自动重启) #define PIN 12 void setup( ...

  9. 折腾了半天,终于搞定了apache的rewrite功能

    基本步骤和网上其它文章说得基本一样.只是在具体操作的时候或多或少存在些问题 一 打开 apache 的配置文件 httpd.conf . 二 将#loadmodule rewrite_module m ...

  10. 嵌入式 hi3518平台获取网络环境中的ip、netmask、broadcast等信息

    <span style="font-family:Courier New;"> /********************************** (C) COPY ...