http://poj.org/problem?id=3216
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 6332 | Accepted: 1701 |
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
Source
题意:一个城市里面有Q个修理站,有M项工作,每个工作有个工作地点pi,最晚开始时间ti,和工作需要的时间di.已经每个站之间的距离,问至少需要几个修理工。
题解:裸的最小路径覆盖,,就加个floyd之前处理下,最小路径覆盖建图是拆点,修理工完成任务i还能到达j连边就行。,,。
顺便当个匈牙利算法的模板
代码:
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-15;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;
const int N=205;
vector<int>g[N];
int cx[N],cy[N];
bool vis[N];
int n1,n2;
bool dfs(int u)
{
for(int i=0;i<g[u].size();i++)
{
int v=g[u][i];
if(!vis[v])
{
vis[v]=true;
if(cy[v]==-1||dfs(cy[v]))
{
cy[v]=u;
cx[u]=v;
return true;
}
}
}
return false;
}
int hungary()
{
int ans=0;
clr1(cx);
clr1(cy);
for(int i=0;i<n1;i++)
{
if(cx[i]==-1)
{
clr(vis);
if(dfs(i))
ans++;
}
}
return ans;
}
struct pa{
int p,t,d;
}b[205];
int a[25][25];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==-1)
a[i][j]=INF;
}
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&b[i].p,&b[i].t,&b[i].d);
g[i].clear();
}
for(int i=0;i<m;i++)
for(int j=i+1;j<m;j++)
{
int t=a[b[i].p-1][b[j].p-1];
if(b[i].t+b[i].d+t<=b[j].t)
g[i].pb(j);
t=a[b[j].p-1][b[i].p-1];
if(b[j].t+b[j].d+t<=b[i].t)
g[j].pb(i);
}
n1=n2=m;
printf("%d\n",n1-hungary());
}
return 0;
}