POJ 3216 Repairing Company

id=3216">题目链接

题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间的时间也知道,问最少须要多少个工人才干完毕任务,即x最少是多少

思路:先floyd求出每两个block之间的最小距离,然后就是最小路径覆盖问题,一个任务之后能赶到还有一个任务就建边

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int N = 25;
const int M = 205;
const int INF = 0x3f3f3f3f; int n, m, q[N][N];
vector<int> g[M]; int in[M], s[M], d[M]; bool judge(int i, int j) {
return s[i] + d[i] + q[in[i]][in[j]] <= s[j];
} int left[M], vis[M]; bool dfs(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (vis[v]) continue;
vis[v] = 1;
if (left[v] == -1 || dfs(left[v])) {
left[v] = u;
return true;
}
}
return false;
} int hungary() {
int ans = 0;
memset(left, -1, sizeof(left));
for (int i = 0; i < m; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main() {
while (~scanf("%d%d", &n, &m) && n) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
scanf("%d", &q[i][j]);
if (q[i][j] == -1) q[i][j] = INF;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
q[i][j] = min(q[i][j], q[i][k] + q[k][j]);
}
}
}
for (int i = 0; i < m; i++) {
g[i].clear();
scanf("%d%d%d", &in[i], &s[i], &d[i]);
for (int j = 0; j < i; j++) {
if (judge(i, j))
g[i].push_back(j);
if (judge(j, i))
g[j].push_back(i);
}
}
printf("%d\n", m - hungary());
}
return 0;
}

POJ 3216 Repairing Company(最小路径覆盖)的更多相关文章

  1. poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)

    http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Su ...

  2. poj 3216 Repairing Company

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

  3. POJ 2594 传递闭包的最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 7171   Accepted: 2 ...

  4. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  5. poj 3020 Antenna Placement (最小路径覆盖)

    链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...

  6. POJ 1548 Robots(最小路径覆盖)

    POJ 1548 Robots 题目链接 题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径 思路:最小路径覆盖问题.一个点假设在还有一个点右下方,就建边.然后跑最小 ...

  7. POJ 1422 二分图(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7278   Accepted: 4318 Descript ...

  8. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  9. POJ 2594 (传递闭包 + 最小路径覆盖)

    题目链接: POJ 2594 题目大意:给你 1~N 个点, M 条有向边.问你最少需要多少个机器人,让它们走完所有节点,不同的机器人可以走过同样的一条路,图保证为 DAG. 很明显是 最小可相交路径 ...

随机推荐

  1. Qt 拖动窗口位置

    Qt 版本 4.8.1 ,主要是为了解决 embeded Qt 下,子窗口的拖动问题. void MyInputPanel::mousePressEvent(QMouseEvent *mouseEve ...

  2. lxml包引入错误

    在使用第三方包lxml引入etree模块时报错: >>> from lxml import etree Traceback (most recent call last): File ...

  3. emplace_back() 和 push_back 的区别(转)

    在引入右值引用,转移构造函数,转移复制运算符之前,通常使用push_back()向容器中加入一个右值元素(临时对象)的时候,首先会调用构造函数构造这个临时对象,然后需要调用拷贝构造函数将这个临时对象放 ...

  4. CentOS 7 安装php5.6,Nginx,Memcached环境及配置

    安装php5.6版本以后不再需要安装Zend Guard,而是用yum命令安装php-opcache及php-pecl-apcu就可以有效的提高php执行速度. 1. 配置yum源 事先确认yum源的 ...

  5. Using Custom Java code in ODI

    在ODI中调用jar包java方法的过程如下: 1.编写Java代码如下 代码写hello world字符串到一个文件. package odi; import java.io.File; impor ...

  6. PHP中使用ActiveMQ实现消息队列

    前面我们已经学了怎样部署ActiveMQ. 我们知道通过ActiveMQ的一个管理后台能够查看任务队列. 今天 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  7. Java 安装和变量环境配置

    //1.分别安装sdk和jre,需要2个均安装才是完整的 //1)jdk_8u60_windows_i586_V8.0.600.27.1440040557 //2)jre_8u60_windows_i ...

  8. <c:url>标签相关知识点

    <c:url>标签: value:指定路径!他会在路径前面自动添加项目名. <c:url value="/index.jsp"/>,他会输出/day14/i ...

  9. Servlet学习(二):ServletConfig获取参数;ServletContext应用:请求转发,参数获取,资源读取;类装载器读取文件

    转载:http://www.cnblogs.com/xdp-gacl/p/3763559.html 一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件 ...

  10. 开源通用型渲染工具-SwiftShader--OpenGL的替代者

    SwiftShader 是一款用于在 CPU 上进行高性能图形渲染的软件库.Google 已经在很多产品中使用该内容库,包括 Chrome.Android 开发工具和云服务.Swiftshader 从 ...