poj 3216 Repairing Company
http://poj.org/problem?id=3216
n个地点,m个任务
每个任务有工作地点,开始时间,持续时间
最少派多少人可以完成所有的任务
传递闭包之后最小路径覆盖
#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define N 21
#define M 201 int n,m; int f[N][N]; bool mp[M][M]; int pos[M],start[M],last[M]; bool vis[M];
int match[M]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} void floyd()
{
for(int k=;k<=n;++k)
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
} void build()
{
memset(mp,false,sizeof(mp));
for(int i=;i<=m;++i)
for(int j=;j<=m;++j)
{
if(i!=j)
{
if(start[i]+last[i]+f[pos[i]][pos[j]]<=start[j]) mp[i][j]=true;
}
}
} bool go(int u)
{
for(int i=;i<=m;++i)
{
if(!vis[i] && mp[u][i])
{
vis[i]=true;
if(!match[i] || go(match[i]))
{
match[i]=u;
return true;
}
}
}
return false;
} void Hungary()
{
memset(match,,sizeof(match));
int cnt=;
for(int i=;i<=m;++i)
{
fill(vis+,vis+m+,);
if(go(i)) cnt++;
}
cout<<m-cnt<<'\n';
} int main()
{
int inf;
while()
{
read(n); read(m);
if(!n) return ;
memset(f,,sizeof(f));
inf=f[][];
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
{
read(f[i][j]);
if(f[i][j]==-) f[i][j]=inf;
} floyd();
for(int i=;i<=m;++i) read(pos[i]),read(start[i]),read(last[i]);
build();
Hungary();
}
}
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 7383 | Accepted: 1993 |
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 pi, ti 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
poj 3216 Repairing Company的更多相关文章
- POJ 3216 Repairing Company(最小路径覆盖)
POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...
- poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)
http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Su ...
- POJ 3216 最小路径覆盖+floyd
Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6646 Accepted: 178 ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- Repairing Company(poj 3216)
题目大意: 有Q个地点,告诉你Q个地点之间的相互距离(从i地点赶到j地点需要的时间).有M项任务, 给你M项任务所在的地点block.开始时间start和任务完成需要时间time.一个工人只有在 他准 ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- 二分+动态规划 POJ 1973 Software Company
Software Company Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1112 Accepted: 482 D ...
- poj 1416 Shredding Company( dfs )
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得 ...
- OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...
随机推荐
- 关于JoptionPane提示框
import java.util.*; import javax.swing.JOptionPane; import javax.swing.UIManager; public class Main ...
- 牛客网国庆集训派对Day5 题目 2018年
链接:https://www.nowcoder.com/acm/contest/205/L来源:牛客网参考博客:https://blog.csdn.net/HTallperson/article/de ...
- IDEA小插件之快速修改Maven多模块的工程版本
Github:https://github.com/zwjlpeng/versions 问题在Maven构建的多模块块程中,如果我们需要修改工程的版本号,会怎么操作呢example例如工程A包括了A- ...
- PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...
- PHP qq第三方登录,install时,报Not Found
最近在学习qq的第三方登录,先在慕课网中观看了相关视频,懂了原理. 然后进行操作时,在下载好SDK后,在../install/install.html中,配置了相关的openid,oppkey,cal ...
- java 数据结构与算法---递归
原理来自百度百科 一.递归的概念 程序调用自身的编程技巧称为递归( recursion).递归做为一种算法在程序设计语言中广泛应用. 一个过程或函数在其定义或说明中有直接或间接调用自身的一种方法,它通 ...
- Spring Boot 推荐的 Java 配置
在学 Spring 的过程中 , 配置文件慢慢的被注解所替代 , 现在 Spring Boot 更是推荐使用 Java 配置完全来代替配置文件 . 需要使用到的注解有 : Bean 相关 : @Con ...
- HDU1565_方格取数(1)
给一个数字方阵,你要从中间取出一些数字,保证相邻的两个数字不同时被取出来,求取出来的最大的和是多少? 建立图模型,对于行列的和为奇数的格子,建立一条从原点到达这个点的边,对于行列和为偶数的格子,建立一 ...
- SPOJ_NSUBSTR
题目意思是给你一个字符串,f[x]是长度为x的子串中,出现个数最多的那个串的出现次数. 给出原串,依次输出f[1],f[2],……. 后缀自动机.对于某一个状态,right[]值的大小就是出现的次数, ...
- python自动化之邮件发送
#!/usr/bin/env python # -*- coding:utf-8 -*- import smtplib from email.mime.multipart import MIMEMul ...