二分图匹配,裸题
本题要点:
1、二分图匹配:
左部点是n个老鼠,右部点是m个鼠洞。当老鼠i和洞j之间的距离超过 s*v 的时候,i和j之间不存在边。
用增光路算法算出最大匹配数 ans。 ans表示可以生存的老鼠, n - ans 表示被吃掉的老鼠。
2、多 case
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
const int MaxN = 110;
int match[MaxN];
double gopher_x[MaxN], gopher_y[MaxN], hole_x[MaxN], hole_y[MaxN];
int n, m;
int s, v;
double step;
bool vis[MaxN];
bool dfs(int x)
{
for(int y = 1; y <= m; ++y)
{
double x1, y1;
x1 = gopher_x[x] - hole_x[y], y1 = gopher_y[x] - hole_y[y];
if(!vis[y] && sqrt(x1 * x1 + y1 * y1) <= (double)(s * v))
{
vis[y] = true;
if(match[y] == 0 || dfs(match[y]))
{
match[y] = x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d%d", &n, &m, &s, &v) != EOF)
{
step = (double)(s * v);
memset(match, 0, sizeof match);
for(int i = 1; i <= n; ++i)
{
scanf("%lf%lf", &gopher_x[i], &gopher_y[i]);
}
for(int i = 1; i <= m; ++i)
{
scanf("%lf%lf", &hole_x[i], &hole_y[i]);
}
int ans = 0;
for(int i = 1; i <= n; ++i)
{
memset(vis, 0, sizeof vis);
if(dfs(i))
++ans;
}
printf("%d\n", n - ans);
}
return 0;
}
/*
2 2 5 10
1.0 1.0
2.0 2.0
100.0 100.0
20.0 20.0
*/
/*
1
*/