题目描述
Description
The gopher family, having averted the canine threat, must face a new predator.
The are n gophers and m gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if a gopher does not reach a hole in s seconds it is vulnerable to being eaten. A hole can save at most one gopher. All the gophers run at the same velocity v. The gopher family needs an escape strategy that minimizes the number of vulnerable gophers.
Input
The input contains several cases. The first line of each case contains four positive integers less than 100: n, m, s, and v. The next n lines give the coordinates of the gophers; the following m lines give the coordinates of the gopher holes. All distances are in metres; all times are in seconds; all velocities are in metres per second.
Output
Output consists of a single line for each case, giving the number of vulnerable gophers.
Sample Input
2 2 5 10
1.0 1.0
2.0 2.0
100.0 100.0
20.0 20.0
Sample Output
1
题目链接
http://poj.org/problem?id=2536
解题思路
题目的大意就是有n只地鼠,m个洞,有一只老鹰,飞到地面的时间是s,地鼠移动的速度是v,询问有几只地鼠会被吃掉。
就是一道简单的二分图模板题。将每只地鼠分别和每个洞进行匹配,算出来的距离除以地鼠移动的速度得出来的时间如果小于s的话,证明地鼠躲在该洞里可以生存,可以建一条边。最后跑一下二分图的模板,算一下最大匹配,算出来的是有多少只地鼠可以匹配到洞,用地鼠的总数量减一下就行了。
AC代码
4096K/125MS/C++1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
struct point
{
double x, y;
} p[205], q[205];
double dist(point a, point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
const int MAXN = 1000;
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int n, m;
bool dfs(int u)
{
for (int v = 1; v <= n; v++)
{
if (g[u][v] && !used[v])
{
used[v] = true;
if (linker[v] == -1 || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int res = 0;
memset(linker, -1, sizeof(linker));
for (int u = 1; u <= m; u++)
{
memset(used, 0, sizeof(used));
if (dfs(u)) res++;
}
return res;
}
int main()
{
double s, v;
while (~scanf("%d%d%lf%lf", &n, &m, &s, &v))
{
for (int i = 1; i <= n; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
}
for (int i = 1; i <= m; i++)
{
scanf("%lf%lf", &q[i].x, &q[i].y);
}
memset(g, 0, sizeof(g));
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
double dis = dist(p[i], q[j]);
if (dis / v <= s)
{
g[i][j] = 1;
}
}
}
printf("%d\n", n - hungary());
}
return 0;
}