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.
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个洞,并且给出它们的坐标。为了防止被鹰吃掉,所有老鼠必须在s秒内全部到达一个洞。
一个洞只能容纳一只老鼠,且认为所有老鼠的速率都是v,请问最终被鹰吃掉的老鼠有多少个?
我们把老鼠当做集合S1,把洞当做集合S2.因为一个洞只能容纳一只老鼠,那么我们认为“老鼠与装老鼠的洞一一对应”。
想到了什么? 没错,二分图匹配!
我们预处理出老鼠到达洞的距离,当且仅当dis/v<=s时,我们给两个对象连边,预处理完毕之后无脑匈牙利即可艹过!
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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 }