POJ 2536 Gopher II 二分图匹配

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8230 Accepted: 3392

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

Waterloo local 2001.01.27

 

题目翻译

有n只老鼠与m个洞,并且给出它们的坐标。为了防止被鹰吃掉,所有老鼠必须在s秒内全部到达一个洞。

一个洞只能容纳一只老鼠,且认为所有老鼠的速率都是v,请问最终被鹰吃掉的老鼠有多少个?

 

我们把老鼠当做集合S1,把洞当做集合S2.因为一个洞只能容纳一只老鼠,那么我们认为“老鼠与装老鼠的洞一一对应”。

想到了什么? 没错,二分图匹配!

我们预处理出老鼠到达洞的距离,当且仅当dis/v<=s时,我们给两个对象连边,预处理完毕之后无脑匈牙利即可艹过!

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cmath>
 5 using namespace std;
 6 const int MAXN=100+10;
 7 int n,m,s,v,ans,match[MAXN];
 8 double dis[MAXN];
 9 bool map[MAXN][MAXN],vis[MAXN];
10 struct data{double x,y;}gop[MAXN],hole[MAXN];
11 inline void init(){ans=0;memset(map,false,sizeof(map));memset(dis,0x3f3f3f3f,sizeof(dis));}
12 inline double calc(int i,int j){
13     double dis=sqrt((hole[j].x-gop[i].x)*(hole[j].x-gop[i].x)+(hole[j].y-gop[i].y)*(hole[j].y-gop[i].y));
14     return (double)(dis/v)<=s;
15 }
16 bool path(int x){
17     for(int i=1;i<=m;i++){
18         if(map[x][i] && !vis[i]){
19             vis[i]=true;
20             if(!match[i]||path(match[i])){match[i]=x;return true;}
21         }
22     }
23     return false;
24 }
25 void hungary(){
26     memset(match,0,sizeof(match));
27     for(int i=1;i<=n;i++){
28         memset(vis,false,sizeof(vis));
29         if(path(i)) ans++;
30     }
31 }
32 int main(){
33     while(scanf("%d%d%d%d",&n,&m,&s,&v)!=EOF){
34         init();
35         for(int i=1;i<=n;i++) scanf("%lf%lf",&gop[i].x,&gop[i].y);
36         for(int i=1;i<=m;i++) scanf("%lf%lf",&hole[i].x,&hole[i].y);
37         for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) map[i][j]=calc(i,j);
38         hungary();
39         printf("%d\n",n-ans);
40     }
41     return 0;
42 }
View Code

 

转载于:https://www.cnblogs.com/scim3/p/5552822.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值