POJ3216——Repairing Company
来源:互联网 发布:交通银行数据中心 编辑:程序博客网 时间:2024/06/09 00:35
Description
Lily runs a repairing company that services the Q blocks in the city. One day the company receivesM repair tasks, the ith of which occurs in block pi, has a deadlineti on any repairman’s arrival, which is also its starting time, and takes a single repairmandi 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 containingQ and M (0 < Q ≤ 20, 0 < M ≤ 200). Then followQ lines each with Q integers, which represent a Q × Q matrix Δ = {δij}, where δij means a bidirectional road connects theith 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 containspi, 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 201 1 101 5 100 0
Sample Output
2
Source
尼玛我想到最小顶点覆盖去了,其实是最小路径覆盖,我们把任务看成点,那么对于每个人,若他修好i之后可以修好j,那么在i,j之间连一条边,说明i和j可以由一个人完成,之后把最小路径覆盖求出来就行,但是要用floyd求出块和块之间的最短路
#include<map> #include<set> #include<list> #include<stack> #include<queue> #include<vector> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; bool vis[210];int mark[210];int mat[25][25];int q, m;struct node{int pi;int ti;int di;}repair[210];struct node2{int next;int to;}edge[210 * 210];int head[210];int tot;void addedge(int from, int to){edge[tot].to = to;edge[tot].next = head[from];head[from] = tot++;}bool dfs(int u){for(int i = head[u]; i != -1; i = edge[i].next){int v = edge[i].to;if(!vis[v]){vis[v] = 1;if(mark[v] == -1 || dfs(mark[v])){mark[v] = u;return true;}} }return false;}int hungary(){int ans = 0;memset( mark, -1, sizeof(mark) );for(int i = 1; i <= m; i++){memset( vis, 0, sizeof(vis) );if(dfs(i))ans++;}return ans;}int main(){while(~scanf("%d%d", &q, &m)){if(!q && !m)break;memset( head, -1, sizeof(head) );tot = 0;for(int i = 1; i <= q; i++)for(int j = 1; j <= q; j++){scanf("%d", &mat[i][j]);if(mat[i][j] == -1)mat[i][j] = 0x3f3f3f3f;}for(int k = 1; k <= q; k++){for(int i = 1; i <= q; i++){for(int j = 1; j <= q; j++){mat[i][j] =min(mat[i][j], mat[i][k] + mat[k][j]);}}}for(int i = 1; i <= m; i++){scanf("%d%d%d", &repair[i].pi, &repair[i].ti, &repair[i].di);}for(int i = 1; i <= m; i++){for(int j = 1; j <= m; j++){if(i == j)continue;int u = repair[i].pi;int v = repair[j].pi;if(mat[u][v] + repair[i].di + repair[i].ti <= repair[j].ti){addedge(i, j);}}}int ans = hungary();printf("%d\n", m - ans);}return 0;}
- POJ3216——Repairing Company
- poj3216 Repairing Company
- POJ3216--Repairing Company
- poj3216 Repairing Company 二分图匹配、最小路径覆盖
- POJ3216 Repairing Company【二分图最小路径覆盖】【Floyd】
- POJ 3216 Repairing Company
- poj 3216 Repairing Company
- poj 3216 Repairing Company 最小路径覆盖
- POJ3216
- POJ 3216 Repairing Company(Floyd + 二分图最大匹配)
- hdu poj 3216 Repairing Company floyd+最小路径覆盖
- POJ 3216 Repairing Company(FLOYD+DAG最小路径覆盖)
- POJ 3216 Repairing Company(最小路径覆盖)
- POJ - 3216 Repairing Company 二分图 最小路径覆盖
- POJ 3216 Repairing Company (floyd + 最小路径覆盖)
- POJ 3216 Repairing Company(FLOYD+DAG最小路径覆盖)
- POJ-3216-Repairing Company(最小路径覆盖)
- POJ 3216 Repairing Company 最少路径覆盖+floyd最短路
- SWT(JFace)体验之GridLayout布局
- 菜鸟逆袭腾讯,杀进三面
- Java 造型运算符(Cast)
- 广州金砖信息技术有限公司测试实习生笔试面试
- POJ3461
- POJ3216——Repairing Company
- comms-logging 输出级别设置
- 开启IAR位定义功能(IAR官方网站提供)
- post & get
- 软考笔记
- 兼容性测试好工具http://www.browserstack.com/
- 好多了吧成熟度和成本单据
- theano 学习
- 关于JButton的测试(无边框等)