有n只老鼠,m个洞,每个洞最多可以藏一只老鼠,每个老鼠的移动速度都是v,给你他们的当前坐标,和洞的坐标,突然老鹰来了,他们必须在s秒内跑到一个洞藏起来,问你最少有多少只老鼠被抓走了。
思路:
二分图匹配裸题,关键就是那句一个洞最多容一只老鼠,对于每个老鼠连接能在s秒内到达的所有洞,然后一边最大匹配,得到的就是最大的藏起来的老鼠sum,输出n - sum就是最少的被抓走的老鼠。
#include<stdio.h>
#include<math.h>
#include<string.h>
#define N_node 100 + 10
#define N_edge 10000 + 100
typedef struct
{
int to ,next;
}STAR;
typedef struct
{
double x ,y;
}NODE;
STAR E[N_edge];
NODE node1[N_node] ,node2[N_node];
int list[N_node] ,tot;
int mk_dfs[N_node] ,mk_gx[N_node];
void add(int a ,int b)
{
E[++tot].to = b;
E[tot].next = list[a];
list[a] = tot;
}
double dis(NODE a ,NODE b)
{
double tmp = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
return sqrt(tmp);
}
int DFS_XYL(int s)
{
for(int k = list[s] ;k; k = E[k].next)
{
int to = E[k].to;
if(mk_dfs[to]) continue;
mk_dfs[to] = 1;
if(mk_gx[to] == -1 || DFS_XYL(mk_gx[to]))
{
mk_gx[to] = s;
return 1;
}
}
return 0;
}
int main ()
{
int n ,m ,i ,j;
double s ,v;
while(~scanf("%d %d %lf %lf" ,&n ,&m ,&s ,&v))
{
for(i = 1 ;i <= n ;i ++)
scanf("%lf %lf" ,&node1[i].x ,&node1[i].y);
for(i = 1 ;i <= m ;i ++)
scanf("%lf %lf" ,&node2[i].x ,&node2[i].y);
memset(list ,0 ,sizeof(list));
tot = 1;
for(i = 1 ;i <= n ;i ++)
for(j = 1 ;j <= m ;j ++)
{
if(dis(node1[i],node2[j]) / v <= s)
add(i ,j);
}
memset(mk_gx ,255 ,sizeof(mk_gx));
int sum = 0;
for(i = 1 ;i <= n ;i ++)
{
memset(mk_dfs ,0 ,sizeof(mk_dfs));
sum += DFS_XYL(i);
}
printf("%d
" ,n - sum);
}
return 0;
}