有n只地鼠的坐标,m个洞的坐标,地鼠的移动速度为v,在s秒以后会飞来一只老鹰要吃地鼠,问有多少个地鼠可能被吃。
解题思路:
二分图最大匹配。
匹配多了一个条件判断距离而已。。。
Gopher II
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5244 | Accepted: 2175 |
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
#include <stdio.h>
#include <vector>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
int flag[305] , visit[305];
struct hole
{
double x,y;
}h[305];
struct gop
{
double x,y;
}p[305];
int n,m,v,s;
double dis( gop p , hole h )
{
return sqrt( (p.x - h.x) * (p.x-h.x) +(p.y-h.y)*(p.y-h.y) );
}
int dfs( int x )
{
for( int i=0 ; i<m ; i++ )
{
if( !visit[i] && dis(p[x],h[i]) <= (double)(s*v) )
{
visit[i] = 1;
if( flag[i] == -1 || dfs(flag[i]) )
{
flag[i] = x;
return true;
}
}
}
return false;
}
int main()
{
while( scanf("%d%d%d%d",&n,&m,&v,&s) != EOF )
{
memset( h , 0 , sizeof(h) );
memset( p , 0 , sizeof(p) );
memset( flag , -1 , sizeof(flag) );
for( int i=0 ; i<n ; i++ )
scanf("%lf%lf",&p[i].x,&p[i].y);
for( int i=0 ; i<m ; i++ )
scanf("%lf%lf",&h[i].x,&h[i].y);
int sum = 0;
for( int i=0 ; i<n ; i++ )
{
memset( visit , 0 , sizeof(visit) );
if( dfs( i ) )
sum++;
}
printf("%d\n",n-sum);
}
return 0;
}