POJ2536 Gopher II(二分图最大匹配)

时间:2023-03-08 16:37:36
Gopher II
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 9005   Accepted: 3724

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

Source

——————————————————————————————————

题目的意思是有n只鼹鼠m个洞,每个洞可以容纳一只鼹鼠,给出坐标和移动速度,问t秒后有多少只不在洞里

思路:把t秒鼹鼠能跑到的洞连一条边,然后跑最大二分图匹配

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
struct point
{
double x,y;
} a[105],b[105]; bool dfs(int u)
{
int v;
for(v=0; v<vN; 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;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int n,m,v,t;
while(~scanf("%d%d%d%d",&n,&m,&v,&t))
{
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
for(int i=0; i<m; i++)
scanf("%lf%lf",&b[i].x,&b[i].y);
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
if((a[i].x-b[j].x)*(a[i].x-b[j].x)+(a[i].y-b[j].y)*(a[i].y-b[j].y)<=1.0*v*t*v*t)
g[i][j]=1;
}
uN=n,vN=m;
printf("%d\n",n-hungary());
}
return 0;
}