Gopher II
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 9003 | Accepted: 3722 |
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个地洞,给你n个地鼠和m个地洞的坐标,地鼠有个移动速度v,s秒后会有一只鹰来抓地鼠,问至少能抓到几只地鼠
解题思路:二分匹配裸题
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <functional>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
int n,m,ss,v;
double x[109],y[109],xx[109],yy[109];
int s[105],nt[10009],e[10009];
int visit[109],visx[109],visy[109];
bool path(int k)
{
for(int i=s[k];~i;i=nt[i])
{
int ee=e[i];
if(!visit[ee])
{
visit[ee]=1;
if(visy[ee]==-1||path(visy[ee]))
{
visy[ee]=k;
visx[k]=ee;
return 1;
}
}
}
return 0;
}
void MaxMatch()
{
int ans=0;
memset(visx,-1,sizeof visx);
memset(visy,-1,sizeof visy);
for(int i=1;i<=n;i++)
{
if(visx[i]==-1)
{
memset(visit,0,sizeof visit);
if(path(i)) ans++;
}
}
printf("%d\n",n-ans);
}
int main()
{
while(~scanf("%d%d%d%d",&n,&m,&ss,&v))
{
for(int i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]);
for(int i=1;i<=m;i++) scanf("%lf%lf",&xx[i],&yy[i]);
memset(s,-1,sizeof s);
int cnt=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if((x[i]-xx[j])*(x[i]-xx[j])+(y[i]-yy[j])*(y[i]-yy[j])<=1.0*ss*v*ss*v)
nt[cnt]=s[i],s[i]=cnt,e[cnt++]=j;
}
}
MaxMatch();
}
return 0;
}