标签:
1 /*
2 匈牙利算法:这题比UVA_670简单,注意是要被吃的鼠的最少个数,套模板
3 */
4 #include <cstdio>
5 #include <algorithm>
6 #include <cstring>
7 #include <cmath>
8 #include <vector>
9 using namespace std;
10
11 const int MAXN = 1e2 + 10;
12 const int INF = 0x3f3f3f3f;
13 struct P
14 {
15 double x, y;
16 }a[MAXN], b[MAXN];
17 bool vis[MAXN];
18 int lk[MAXN];
19 vector<int> G[MAXN];
20
21 double get_dis(double x1, double y1, double x2, double y2)
22 {
23 return sqrt ((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2));
24 }
25
26 bool DFS(int u)
27 {
28 for (int i=0; i<G[u].size (); ++i)
29 {
30 int v = G[u][i];
31 if (!vis[v])
32 {
33 vis[v] = true;
34 if (lk[v] == -1 || DFS (lk[v]))
35 {
36 lk[v] = u; return true;
37 }
38 }
39 }
40
41 return false;
42 }
43
44 int hungary(int n)
45 {
46 int res = 0; memset (lk, -1, sizeof (lk));
47 for (int i=1; i<=n; ++i)
48 {
49 memset (vis, false, sizeof (vis));
50 if (DFS (i)) res++;
51 }
52
53 return res;
54 }
55
56 int main(void) //UVA 10080 Gopher II
57 {
58 // freopen ("UVA_10080.in", "r", stdin);
59
60 int n, m, s, v;
61 while (scanf ("%d%d%d%d", &n, &m, &s, &v) == 4)
62 {
63 for (int i=1; i<=n; ++i) scanf ("%lf%lf", &a[i].x, &a[i].y);
64 for (int i=1; i<=m; ++i) scanf ("%lf%lf", &b[i].x, &b[i].y);
65 for (int i=1; i<=n; ++i) G[i].clear ();
66 for (int i=1; i<=n; ++i)
67 {
68 for (int j=1; j<=m; ++j)
69 {
70 if (get_dis (a[i].x, a[i].y, b[j].x, b[j].y) <= s * v) G[i].push_back (j);
71 }
72 }
73
74 printf ("%d\n", n - hungary (n));
75 }
76
77 return 0;
78 }
二分图匹配(匈牙利算法) UVA 10080 Gopher II
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4652307.html