Rain on your ParadeTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 3305 Accepted Submission(s): 1063
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.
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.
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
Sample Output
|
题意:距离下雨还有time时间。现在给你n个人的位置和速度(每秒跑多少米)以及m把伞的位置,已知每把伞只能被一个人使用,问你最多有多少人可以不被淋。
记人和伞距离为dis,人的速度为speed。
思路:满足dis * dis <= time * time * speed * speed,则人向伞建边,然后HK。
AC代码:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define MAXN 3000+10
using namespace std;
struct Point{
int x, y, speed;
};
Point num[MAXN];
int dx[MAXN], dy[MAXN];
int mx[MAXN], my[MAXN];
bool used[MAXN];
vector<int> G[MAXN];
int numx, numy;
int dis(int x1, int y1, int x2, int y2){
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int DFS(int u)
{
for(int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if(!used[v] && dy[v] == dx[u] + 1)
{
used[v] = true;
if(my[v] == -1 || DFS(my[v]))
{
my[v] = u; mx[u] = v;
return 1;
}
}
}
return 0;
}
int k = 1;
void HK_match()
{
memset(mx, -1, sizeof(mx));
memset(my, -1, sizeof(my));
int ans = 0;
while(1)
{
bool flag = false;
memset(dx, 0, sizeof(dx));
memset(dy, 0, sizeof(dy));
queue<int> Q;
for(int i = 1; i <= numx; i++)
if(mx[i] == -1) Q.push(i);
while(!Q.empty())
{
int u = Q.front();
Q.pop();
for(int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if(!dy[v])
{
dy[v] = dx[u] + 1;
if(my[v] != -1)
{
dx[my[v]] = dx[u] + 1;
Q.push(my[v]);
}
else
flag = true;
}
}
}
if(!flag) break;
memset(used, false, sizeof(used));
for(int i = 1; i <= numx; ++i)
if(mx[i] == -1)
ans += DFS(i);
}
printf("Scenario #%d:\n%d\n\n", k++, ans);
}
void getMap()
{
int time;
scanf("%d", &time);
scanf("%d", &numx);
for(int i = 1; i <= numx; i++)
scanf("%d%d%d", &num[i].x, &num[i].y, &num[i].speed), G[i].clear();
scanf("%d", &numy);
for(int i = 1; i <= numy; i++)
{
int X, Y;
scanf("%d%d", &X, &Y);
for(int j = 1; j <= numx; j++)
if(dis(X, Y, num[j].x, num[j].y) <= num[j].speed * num[j].speed * time * time)
G[j].push_back(i);
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
getMap();
HK_match();
}
return 0;
}