poj 2060(最小路径覆盖)

 1 // File Name: 2060.cpp
 2 // Author: Missa
 3 // Created Time: 2013/2/11 星期一 17:11:30
 4 
 5 //最小路径覆盖数=顶点数-二分图最大匹配数
 6 #include<iostream>
 7 #include<cstdio>
 8 #include<cstring>
 9 #include<algorithm>
10 #include<cmath>
11 #include<queue>
12 #include<stack>
13 #include<string>
14 #include<vector>
15 #include<cstdlib>
16 #include<map>
17 using namespace std;
18 
19 const int maxn = 5e2+5;
20 int n;
21 struct Cust
22 {
23     int src;
24     int x1,y1,x2,y2;
25     int end;
26 }cust[maxn];
27 //*******************匈牙利算法*************************
28 int nx,ny;
29 bool vis[maxn];
30 int ma[maxn][maxn];
31 int link[maxn];
32 bool dfs(int x)
33 {
34     for(int y=1;y<=ny;y++)
35     {
36         if(!vis[y] && ma[x][y])
37         {
38             vis[y]=1;
39             if(link[y]==-1 || dfs(link[y]))
40             {
41                 link[y]=x;
42                 return true;
43             }
44         }
45     }
46     return false;
47 }
48 int maxmatch()
49 {
50     int c=0;
51     memset(link,-1,sizeof(link));
52     for(int x=1;x<=nx;x++)
53     {
54         memset(vis,0,sizeof(vis));
55         if(dfs(x)) c++;
56     }
57     return c;
58 }
59 //******************************************************
60 bool ok(int i,int j)
61 {
62     if(cust[i].end+abs(cust[i].x2-cust[j].x1)+abs(cust[i].y2-cust[j].y1)<cust[j].src)
63         return true;
64     return false;
65 }
66 int main()
67 {
68     int t;
69     scanf("%d",&t);
70     while(t--)
71     {
72         scanf("%d",&n);
73         memset(cust,0,sizeof(cust));
74         for(int i=1;i<=n;i++)
75         {
76             int a,b;
77             scanf("%d:%d",&a,&b);
78             cust[i].src=a*60+b;
79             scanf("%d%d%d%d",&cust[i].x1,&cust[i].y1,&cust[i].x2,&cust[i].y2);
80             cust[i].end=cust[i].src+abs(cust[i].x1-cust[i].x2)+abs(cust[i].y1-cust[i].y2);
81         }
82         memset(ma,0,sizeof(ma));
83         for(int i=1;i<=n;i++)
84         {
85             for(int j=1;j<=n;j++)
86             {
87                 if(i==j) continue;
88                 if(ok(i,j)) ma[i][j]=1;
89             }
90         }
91         nx=ny=n;
92         printf("%d\n",n-maxmatch());
93     }
94     return 0;
95 }

 

posted @ 2013-02-11 19:58  Missa  阅读(201)  评论(0编辑  收藏  举报