POJ-3216-Repairing Company(最小路径覆盖)
2016-05-03 20:27
816 查看
Language: Default Repairing Company
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 Source |
根据题意,可以计算出两点之间的可达关系,根据可达关系建图,求出最大匹配,
最小路径覆盖=N-最大匹配。
floyd都写错了找了半天bug mdzz。OTZ。。。。
#include <iostream> #include <cstdio> #include <cstring> #include <set> #include <queue> #include <cmath> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f #define bug cout<<"bug\n" const int MAXN = 207; const int MAXM = 1e6+7; int map_[MAXN][MAXN]; int cost[MAXN][MAXN]; int n,m; struct node { int id; int start,endd; } task[MAXN]; int link[MAXN],vis[MAXN]; int DFS(int u) { for(int v=0; v<m; ++v) if(map_[u][v] && !vis[v]) { vis[v]=1; if(link[v]==-1 || DFS(link[v])) { link[v]=u; return 1; } } return 0; } int hungary() { int ans=0; memset(link,-1,sizeof(link)); for(int u=0; u<m; ++u) { memset(vis,0,sizeof(vis)); ans+=DFS(u); } return ans; } void floyd() { for(int k=0; k<n; ++k) for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(cost[i][j]>cost[i][k]+cost[k][j]) cost[i][j]=cost[i][k]+cost[k][j]; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { if(!n||!m)break; memset(cost,INF,sizeof(cost)); memset(map_,0,sizeof(map_)); for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) { scanf("%d",&cost[i][j]); if(cost[i][j]==-1)cost[i][j]=INF; } for(int i=0; i<m; ++i) { int c; scanf("%d%d%d",&task[i].id,&task[i].start,&c); task[i].endd=task[i].start+c; } floyd(); for(int i=0; i<m; ++i) for(int j=0; j<m; ++j) if(i!=j && task[j].start-task[i].endd>=cost[ task[i].id-1 ][ task[j].id-1 ]) map_[i][j]=1; cout<<m-hungary()<<endl; } return 0; }
相关文章推荐
- wait和waitpid函数
- POJ 1422 Air Raid
- Air Infomation System 基于控制台的航班信息系统(方法总结)
- Intel S5000VSA(SAS)主板设置RAID 步骤【转】
- linker command failed with exit code 1 (use -v to see invocation)
- WM_PAINT 消息与 OnDraw、OnPaint()
- IDEA快捷键 如syso(sout Tab键)main(psvm Tab键)
- CodeForces 616E Sum of Remainders(数论)
- 山东省第一届ACM大学生程序设计竞赛 Fairy tale 大模拟
- samba “The specified network name is no longer available” 出错的解决办法
- 利用正则表达式:找到一段字符串中所有的IP地址和Email地址
- TensorFlow教程02:针对机器学习初学者的MNIST实验——Softmax回归
- mac上google chrome helper占内存,mac air 发热
- rails路由全解
- 在foxmail和outlook中设置QQ邮箱、gmail邮箱、新浪邮箱、微软邮箱、网易邮箱等的方法
- 【STL】SGI STL私房菜:_type_traits
- Failure to transfer org.apache.maven:maven-archiver:jar:x.x from https://repo.maven.apache.org/maven
- Rails技巧之tap&try
- androidStudio-importProject异常-Error:(1, 0) Your project path contains non-ASCII characters.
- HDU 4300 Clairewd’s message(扩展kmp)