HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法
题目链接: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
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.
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.
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
2
Scenario #2:
2
题解:
就直接求二分图最大匹配,不过由于数据较大,匈牙利算法超时,所以需要用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算法的更多相关文章
- 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 ...
- 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 ...
- HDU2389:Rain on your Parade(二分图最大匹配+HK算法)
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
- SPOJ 4206 Fast Maximum Matching (二分图最大匹配 Hopcroft-Carp 算法 模板)
题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围: 1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应 ...
- 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 ...
- Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)
题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...
- UESTC 919 SOUND OF DESTINY --二分图最大匹配+匈牙利算法
二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). ...
- HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 51Nod 2006 飞行员配对(二分图最大匹配)-匈牙利算法
2006 飞行员配对(二分图最大匹配) 题目来源: 网络流24题 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 第二次世界大战时期,英国皇家空军从沦陷国 ...
随机推荐
- SQL2012通用分页存储过程
--提取分页数据,返回总记录数 Createprocedure [dbo].[sp_Common_GetDataPaging_ReturnDataCount] ( @SqlString varchar ...
- [luoguP3068] [USACO13JAN]派对邀请函Party Invitations(stl大乱交)
传送门 记录每一个编号在那些组中,可以用vector,这里选择链式前向星. 每一组用set 将被邀请的放到queue中 #include <set> #include <queue& ...
- vs code 使用心得
Jetbrains 家族的软件适合java,python开发,但是对与rust,shell等的开发,则显得有些臃肿,需要一款轻快的编辑器,经过挑选,在sublime3 与 vs code 中选则了vs ...
- CERC 2014 (动态树+主席树)
CERC 2014 Pork barrel Problem : n个点m条边有边权的无向图,有q个询问,每次询问权值在[L,R]内的边组成的最小生成树的权值和,强制在线. n <= 1000, ...
- mysql 获取所有的数据库名字
mysql 获取所有的数据库名字 一.如果使用的是mysqli: $con = @mysqli_connect("localhost", "root", &qu ...
- Mac BOOK PRO U盘安装windows7、8及8.1
http://v.youku.com/v_show/id_XMTI1NjgzMzU0NA==.html http://jingyan.baidu.com/article/1709ad80b3d2f44 ...
- hybird app 用 xcode ios打包 ipa 测试包并且安装真机测试
1.创建 ios 项目 1.用 cordova 创建一个 ios 项目 npm install -g cordova cordova create hello com.mydomain.hello H ...
- java下XML与JSON互相转换的Utils类
原文:http://heipark.iteye.com/blog/1394844 需要json-lib-2.1-jdk15.jar和xom-1.2.5.jar,maven pom.xml如下: < ...
- Mysql不同存储引擎的表转换方法
Mysql不同存储引擎的表转换方法 1.Alter table直接修改表的存储引擎,但是这样会导致大量的系统开销,Mysql为此要执行一个就表向新表的逐行复制.在此期间,转换操作可能会占用服务器的所有 ...
- 【nginx】【转】Nginx核心进程模型
一.Nginx整体架构 正常执行中的nginx会有多个进程,最基本的有master process(监控进程,也叫做主进程)和woker process(工作进程),还可能有cache相关进程. ...