二分图匹配
View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define MAXN 105
struct Point
{
double x, y;
} gopher[MAXN], hole[MAXN];
int uN, vN, v, s;
bool g[MAXN][MAXN];
int xM[MAXN], yM[MAXN];
bool chk[MAXN];
bool SearchPath(int u)
{
int v;
for (v = 0; v < vN; v++)
if (g[u][v] && !chk[v])
{
chk[v] = true;
if (yM[v] == -1 || SearchPath(yM[v]))
{
yM[v] = u;
xM[u] = v;
return true;
}
}
return false;
}
int MaxMatch()
{
int u, ret = 0;
memset(xM, -1, sizeof(xM));
memset(yM, -1, sizeof(yM));
for (u = 0; u < uN; u++)
if (xM[u] = -1)
{
memset(chk, false, sizeof(chk));
if (SearchPath(u))
ret++;
}
return ret;
}
void input()
{
for (int i = 0; i < uN; i++)
scanf("%lf%lf", &gopher[i].x, &gopher[i].y);
for (int i = 0; i < vN; i++)
scanf("%lf%lf", &hole[i].x, &hole[i].y);
}
void work()
{
for (int i = 0; i < uN; i++)
for (int j = 0; j < vN; j++)
if (sqrt((gopher[i].x - hole[j].x) * (gopher[i].x - hole[j].x) + (gopher[i].y - hole[j].y) * (gopher[i].y - hole[j].y)) <= v * s)
g[i][j] = true;
else
g[i][j] = false;
}
int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d%d%d%d", &uN, &vN, &s, &v) != EOF)
{
input();
work();
printf("%d\n", uN - MaxMatch());
}
return 0;
}