openjudge GoperII

来源:互联网 发布:语音数据统计校对员 编辑:程序博客网 时间:2024/06/11 13:47

1538:Gopher II

  • 查看
  • 提交
  • 统计
  • 提问
总时间限制: 
2000ms 
内存限制: 
65536kB
描述
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 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 consists of a single line for each case, giving the number of vulnerable gophers.
样例输入
2 2 5 101.0 1.02.0 2.0100.0 100.020.0 20.0
样例输出
1
题目大意:N只老鼠,M个洞,每个洞只能容纳一只老鼠,老鼠有S秒的时间逃跑,每只老鼠的速度均为V,问时间结束后至少有多少只老鼠会有危险

Waterloo local 2001.01.27

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int f[110][110],n,m,i,j,s,v,num;
double x1[110],y11[110],x2[110],y2[110];
int used[110],hole[110];
bool find(int x)
{
for (int k=1;k<=m;k++)
{
if (f[x][k]==1&&used[k]==0)
{
used[k]=1;
if (find(hole[k])||hole[k]==0)
 {
           hole[k]=x;
   return true;
 }
}
}
return false;
}
int main()
{
  while(scanf("%d%d%d%d",&n,&m,&s,&v)==4)
   {
    memset(f,0,sizeof(f));
    memset(hole,0,sizeof(hole));
for (i=1;i<=n;i++)
scanf("%lf%lf",&x1[i],&y11[i]);
for (i=1;i<=m;i++)
scanf("%lf%lf",&x2[i],&y2[i]);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
  {
  double len=sqrt(fabs(x1[i]-x2[j])*fabs(x1[i]-x2[j])+fabs(y11[i]-y2[j])*fabs(y11[i]-y2[j]));
  if (len<=s*v)
   {
   f[i][j]=1;
   }
  }
num=0;
for (i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
if (find(i))  num++;
}
printf("%d\n",n-num);
   }
} //匈牙利算法二分图的最大匹配

0 0
原创粉丝点击