题目链接:https://vjudge.net/problem/HDU-2389

Rain on your Parade

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 4889    Accepted Submission(s): 1612

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 <= si <= 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
 
Recommend
lcy

题解:

就直接求二分图最大匹配,不过由于数据较大,匈牙利算法超时,所以需要用HK算法。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9+;
const int MAXN = +; struct Node
{
int x, y, speed;
}gue[MAXN], umb[MAXN]; int uN, vN, t;
vector<int>g[MAXN]; int Mx[MAXN], My[MAXN];
int dx[MAXN], dy[MAXN];
int dis;
bool used[MAXN]; bool SearchP()
{
queue<int>Q;
dis = INF;
memset(dx, -, sizeof(dx));
memset(dy, -, sizeof(dy));
for(int i = ; i<=uN; i++)
if(Mx[i]==-)
{
Q.push(i);
dx[i] = ;
} while(!Q.empty())
{
int u = Q.front();
Q.pop();
if(dx[u]>dis) break;
int sz = g[u].size();
for(int i = ; i<sz; i++)
{
int v = g[u][i];
if(dy[v]==-)
{
dy[v] = dx[u] + ;
if(My[v]==-) dis = dy[v];
else
{
dx[My[v]] = dy[v] + ;
Q.push(My[v]);
}
}
}
}
return dis!=INF;
} bool DFS(int u)
{
int sz = g[u].size();
for(int i = ; i<sz; i++)
{
int v = g[u][i];
if(!used[v] && dy[v]==dx[u]+)
{
used[v] = true;
if(My[v]!=- && dy[v]==dis) continue;
if(My[v]==- || DFS(My[v]))
{
My[v] = u;
Mx[u] = v;
return true;
}
}
}
return false;
} int MaxMatch()
{
int res = ;
memset(Mx, -, sizeof(Mx));
memset(My, -, sizeof(My));
while(SearchP())
{
memset(used, false, sizeof(used));
for(int i = ; i<=uN; i++)
if(Mx[i]==- && DFS(i))
res++;
}
return res;
} int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &t, &uN);
for(int i = ; i<=uN; i++)
{
scanf("%d%d%d", &gue[i].x, &gue[i].y, &gue[i].speed);
g[i].clear();
} scanf("%d", &vN);
for(int i = ; i<=vN; i++)
scanf("%d%d", &umb[i].x, &umb[i].y); for(int i = ; i<=uN; i++)
for(int j = ; j<=vN; j++)
{
int dis = (gue[i].x-umb[j].x)*(gue[i].x-umb[j].x)
+(gue[i].y-umb[j].y)*(gue[i].y-umb[j].y);
int s = gue[i].speed*gue[i].speed*t*t;
if(s>=dis) g[i].push_back(j);
} int ans = MaxMatch();
printf("Scenario #%d:\n%d\n\n", ++kase, ans); }
}

HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法的更多相关文章

  1. hdu2389 Rain on your Parade 二分图匹配--HK算法

    You’re giving a party in the garden of your villa by the sea. The party is a huge success, and every ...

  2. hdu-2389.rain on your parade(二分匹配HK算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  3. HDU2389:Rain on your Parade(二分图最大匹配+HK算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  4. SPOJ 4206 Fast Maximum Matching (二分图最大匹配 Hopcroft-Carp 算法 模板)

    题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围:  1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应 ...

  5. Hdu2389 Rain on your Parade (HK二分图最大匹配)

    Rain on your Parade Problem Description You’re giving a party in the garden of your villa by the sea ...

  6. Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)

    题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...

  7. UESTC 919 SOUND OF DESTINY --二分图最大匹配+匈牙利算法

    二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). ...

  8. HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  9. 51Nod 2006 飞行员配对(二分图最大匹配)-匈牙利算法

    2006 飞行员配对(二分图最大匹配) 题目来源: 网络流24题 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 第二次世界大战时期,英国皇家空军从沦陷国 ...

随机推荐

  1. Oracle 释放过度使用的Undo表空间

    故障现象:UNDO表空间越来越大,长此下去最终数据因为磁盘空间不足而崩溃: 问题分析:产生问题的原因主要以下两点: 1. 有较大的事务量让Oracle Undo自动扩展,产生过度占用磁盘空间的情况: ...

  2. iOS第三方地图-百度地图中心点定位

    使用百度地图定位后,滑动地图,使用反编码确定地图中心店的位置信息 // // MapControl.m // quyizu // // Created by apple on 15/9/2. // C ...

  3. 洛谷P2058 海港

    题目描述 小K是一个海港的海关工作人员,每天都有许多船只到达海港,船上通常有很多来自不同国家的乘客. 小K对这些到达海港的船只非常感兴趣,他按照时间记录下了到达海港的每一艘船只情况:对于第i艘到达的船 ...

  4. 【PD】PowerDesigner生成数据字典

    1.首先说明我使用的环境 --------------------------------第一种:不按模板导出导出数据字典----------------------------- 2.打开PDM模型 ...

  5. Assigning to "id<CALayerDelegate> _Nullable" from incompatible type "ZXCapture *const __strong" 的警告提示信息

    该警告提示信息,是说,设置了代理对象,但是并没有继承它的代理.下图中,可以看出,警告信息提示我们没有继承“CALayerDelegate”的代理. 解决方法,很简单,(在 @interface 文件中 ...

  6. kafka调试中遇到Connection to node -1 could not be established. Broker may not be available.

    https://blog.csdn.net/Mr_Hou2016/article/details/79484032

  7. jfree-生成xy图

    需要导入的包: import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data ...

  8. eclipse需要的环境变量就两个,一个是java_home指向JDK。另一个是Tomcat,自己去preference-sever下new一个

    1.eclipse需要的环境变量就两个,一个是java_home指向JDK.另一个是Tomcat,自己去preference-sever下new一个

  9. 临远大神,你为啥要建立一个 TASK表。HumanTaskDTO

    临远大神,你为啥要建立一个 TASK表.HumanTaskDTO HumanTask这张表的作用是什么. 为了实现理想中的任务中心.TaskCenter. 首先,工作流可能会完全不包含任何人工节点,全 ...

  10. 纠结的链接——ln、ln -s、fs.symlink、require

    纠结的链接--ln.ln -s.fs.symlink.require 提交 我的留言 加载中 已留言 inode 我们首先来看看 linux 系统里面的一个重要概念:inode. 我们知道,文件存储在 ...