题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389
Problem Description
You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It’s a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It could be the perfect end of a beautiful day.
But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, “I know that breeze! It means its going to rain heavily in just a few minutes!” Your guests all wear their best dresses and really would not like to get wet, hence they stand terrified when hearing the bad news.
You have prepared a few umbrellas which can protect a few of your guests. The umbrellas are small, and since your guests are all slightly snobbish, no guest will share an umbrella with other guests. The umbrellas are spread across your (gigantic) garden, just like your guests. To complicate matters even more, some of your guests can’t run as fast as the others.
Can you help your guests so that as many as possible find an umbrella before it starts to pour?
Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, find out how many of your guests can at most reach an umbrella. Two guests do not want to share an umbrella, however.
But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, “I know that breeze! It means its going to rain heavily in just a few minutes!” Your guests all wear their best dresses and really would not like to get wet, hence they stand terrified when hearing the bad news.
You have prepared a few umbrellas which can protect a few of your guests. The umbrellas are small, and since your guests are all slightly snobbish, no guest will share an umbrella with other guests. The umbrellas are spread across your (gigantic) garden, just like your guests. To complicate matters even more, some of your guests can’t run as fast as the others.
Can you help your guests so that as many as possible find an umbrella before it starts to pour?
Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, find out how many of your guests can at most reach an umbrella. Two guests do not want to share an umbrella, however.
Input
The input starts with a line containing a single integer, the number of test cases.
Each test case starts with a line containing the time t in minutes until it will start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= 3000), followed by m lines containing x- and y-coordinates as well as the speed si in units per minute (1 <= s i <= 3000) of the guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <= 3000), the number of umbrellas, followed by n lines containing the integer coordinates of each umbrella, separated by a space.
The absolute value of all coordinates is less than 10000.
Each test case starts with a line containing the time t in minutes until it will start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= 3000), followed by m lines containing x- and y-coordinates as well as the speed si in units per minute (1 <= s i <= 3000) of the guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <= 3000), the number of umbrellas, followed by n lines containing the integer coordinates of each umbrella, separated by a space.
The absolute value of all coordinates is less than 10000.
Output
For each test case, write a line containing “Scenario #i:”, where i is the number of the test case starting at 1. Then, write a single line that contains the number of guests that can at most reach an umbrella before it starts to rain. Terminate every test case with a blank line.
Sample Input
2 1 2 1 0 3 3 0 3 2 4 0 6 0 1 2 1 1 2 3 3 2 2 2 2 4 4
Sample Output
Scenario #1: 2 Scenario #2: 2
Source
题意:在一个二维坐标上有n个人,m个伞,每个人有各自的速度。问友多少人可以在tmin内移动到不同的雨伞出,即两个人不能公用一把伞。
分析:雨伞和人是一一对应的关系,分别为两个集合。对于每个人来说,在tmin内可以得到一个圆形的活动范围,只要这个范围内有伞,就得到一个对应关系。建图时,X={人集合},Y={伞集合},E={i,j|(uxj-xi)*(uxj-xi)+(uyj-yi)*(uyj-yi)}<=(t*si)*(t*si) 这里以人的坐标为圆心,tmin内的距离为半径构成的圆,只要雨伞的坐标满足该不等式,则得到一个对应关系。由于该题的m和n都是3000,所以用匈牙利算法可能会TLE,所以用Hopcroft_Karp[算法
代码:
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=3005;
const int inf=1<<28;
int bmap[maxn][maxn];
int cx[maxn],cy[maxn];
int nx,ny;
int dx[maxn],dy[maxn];
int dis;
int n,m;
bool bmask[maxn];
struct node
{
int x,y,s;
}a[maxn],b[maxn];
bool search()
{
queue<int>q;
dis=inf;
memset(dx,-1,sizeof(dx));
memset(dy,-1,sizeof(dy));
for(int i=0;i<nx;i++)
{
if(cx[i]==-1)
{
q.push(i);
dx[i]=0;
}
}
while(!q.empty())
{
int u=q.front();
q.pop();
if(dx[u]>dis)
break;
for(int v=0;v<ny;v++)
{
if(bmap[u][v]&&dy[v]==-1)
{
dy[v]=dx[u]+1;
if(cy[v]==-1)
dis=dy[v];
else
{
dx[cy[v]]=dy[v]+1;
q.push(cy[v]);
}
}
}
}
return dis!=inf;
}
int find(int u)
{
for(int v=0;v<ny;v++)
{
if(!bmask[v]&&bmap[u][v]&&dy[v]==dx[u]+1)
{
bmask[v]=1;
if(cy[v]!=-1&&dy[v]==dis)
continue;
if(cy[v]==-1||find(cy[v]))
{
cy[v]=u;
cx[u]=v;
return 1;
}
}
}
return 0;
}
int match()
{
int res=0;
memset(cx,-1,sizeof(cx));
memset(cy,-1,sizeof(cy));
while(search())
{
memset(bmask,0,sizeof(bmask));
for(int i=0;i<nx;i++)
{
if(cx[i]==-1)
res+=find(i);
}
}
return res;
}
int main()
{
//freopen("in.txt","r",stdin);
int ca;
scanf("%d",&ca);
int num=1;
while(ca--)
{
memset(bmap,0,sizeof(bmap));
int t;
scanf("%d",&t);
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].s);
scanf("%d",&m);
nx=n;
ny=m;
for(int i=0;i<m;i++)
scanf("%d %d",&b[i].x,&b[i].y);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(((b[j].x-a[i].x)*(b[j].x-a[i].x)+(b[j].y-a[i].y)*(b[j].y-a[i].y))<=t*a[i].s*t*a[i].s)
bmap[i][j]=1;
}
// for(int i=0;i<n;i++)
// {
// for(int j=0;j<m;j++)
// printf("%d ",bmap[i][j]);
// printf("\n");
// }
printf("Scenario #%d:\n%d\n\n",num++,match());
}
return 0;
}