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 ...
随机推荐
- 浅学JavaScript
JavaScript是互联网上最流行的脚本语言,可广泛用于服务器.PC.笔记本电脑智能手机等设备: 对事件的反应: <!DOCTYPE html> <html> <hea ...
- printf in KEIL C51
转自:http://blog.csdn.net/it1988888/article/details/8821713 在keil中printf默认是向串口中发送数据的,所以,如果应用该函数,必须先初始化 ...
- python基础(四)文件操作和集合
一.文件操作 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句柄操作文件 3.关闭文件. 1.文件基本操作: f = open('file.txt','r') # ...
- selenium使用execl实现数据驱动测试
import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.uti ...
- DataRow数组根据指定列排序
正序:DataRow[] datarow = datarow.OrderBy(x=>x["Ybrq"]).ToArray(); 倒序:DataRow[] datarow = ...
- 我的虚拟机中的 centOS 连不了网了
网上的办法试过了,查看虚拟机的网络配置,是 NET的, 也 cd 到/etc/sysconfig/network-script/ifcfg-eth0 里面看了,onboot 本来就是 yes,要不然我 ...
- Redis:主从复制
前言 在前面的两篇文章中,分别介绍了Redis的内存模型和Redis的持久化. 在Redis的持久化中曾提到,Redis高可用的方案包括持久化.主从复制(及读写分离).哨兵和集群.其中持久化侧重解决的 ...
- div内元素的居中
1.如果是一行文字(不超过一行) parent{ text-align:center; line-height:div高度; } 2.如果是div内其他类型元素 parent{ height:xxxp ...
- shell的sed命令
sed命令用于在线编辑文本,它一次处理一行内容. 命令语法: sed [-n/e/f/r/i] [cmd] [InFile] 参数解释: 选项与参数: -n: quiet/silent,安静模式,经过 ...
- bzoj 1036: [ZJOI2008]树的统计Count (树链剖分+线段树 点权)
1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 21194 Solved: 8589[Submit ...