拿他来学了学二分图的最大匹配,搞清楚原理之后,算法比较简单,这个博客讲的很好,细心看十分钟就看明白了
核心就是在于不断地dfs来找到合适的匹配
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>
#include <math.h>
#include <fstream>
#include <map>
#include <algorithm>
using namespace std;
const int maxn = 505;
struct node {
double x, y;
node(double x0=0.0,double y0=0.0){
x=x0;
y=y0;
}
}G[maxn],H[maxn];
int n, m, s, v, match[maxn];
bool mmap[maxn][maxn], visited[maxn];
node dishu[maxn], holes[maxn];
double dist(node a, node b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int dfs(int x){
for (int i = n+1; i <= n+m ; i++) {
if (!visited[i]&&mmap[x][i]) {
visited[i] = 1;
if (match[i] == -1 || dfs(match[i])) {
match[i] = x;
return 1;
}
}
}
return 0;
}
int main(){
while (~scanf("%d%d%d%d",&n, &m, &s, &v)) {
memset(match, -1, sizeof(match));
memset(mmap, 0, sizeof(mmap));
for (int i = 1; i <= n; i++) {
scanf("%lf%lf", &G[i].x, &G[i].y);
}
for (int i = 1; i <= m; i++) {
scanf("%lf%lf", &H[i].x, &H[i].y);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
double dis = dist(G[i], H[j]);
if (dis/v <= (double) s) {
mmap[i][n+j] = true;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
memset(visited,0,sizeof(visited));
ans+=dfs(i);
}
printf("%d\n",n-ans);
}
return 0;
}