Gopher II
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
题目意思:有n只老鼠 m个老鼠洞 每只老鼠的速度v 当老鹰来的时候 如果老鼠能在s秒内进洞 就能不死
求 死的老鼠的个数最少。
最小点覆盖 = 点数 - 最大匹配。
这个题的关键就是建图 只要能把图建出来 剩下的就是匈牙利算法的模板了 。。。
可怜 传参时把double 传成int wa了n次 。。fuck!!
算出每只老鼠到每个洞的距离 如果距离 < s*v map[i][j] = 1;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
int map[110][110],vist[110],link[110];
int n,m,s,v;
double distt (double x1,double y1,double x2,double y2)///fuck!!
{
double s = sqrt ( (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
return s;
}
int dfs (int x)
{
for (int i = 1; i <= m; i++)
{
if ( map[x][i] && vist[i] == 0)
{
vist[i] = 1;
if ( link[i] == -1 || dfs (link[i]))
{
link[i] = x;
return 1;
}
}
}
return 0;
}
void print ()
{
for (int i =1; i <= n; i ++)
{
for (int j = 1; j <= m; j++)
printf ("%d ",map[i][j]);
printf ("\n");
}
}
int main ()
{
double nx[1110],ny[1110],mx[1110],my[1110];
while (~scanf ("%d%d%d%d",&n,&m,&s,&v))
{
memset (link , -1,sizeof (link));
memset (map,0,sizeof (map));
int sum = s * v;
for (int i = 1; i <= n; i++)
scanf ("%lf%lf",&nx[i],&ny[i]);
for (int i = 1 ; i <= m; i++)
{
scanf ("%lf%lf",&mx[i],&my[i]);
for (int j = 1; j <= n; j++) ///mouse
{
double dist = distt (mx[i],my[i],nx[j],ny[j]);
// printf (" %d -> %d dist = %lf\n",j,i,dist);
if ( dist <= sum )
map[j][i] = 1;
}
}
// print ();
int cou = 0;
for (int i = 1; i <= n; i++) ///mouse
{
memset (vist,0,sizeof (vist));
if (dfs (i))
cou ++;
}
printf ("%d\n",n - cou);
}
return 0;
}