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 难度:基础题 收藏 关注 第二次世界大战时期,英国皇家空军从沦陷国 ...
随机推荐
- PS学习笔记(03)
ui到底是什么? 很多同学不知道ui是什么,以为画个ICON图标就是做ui了,导致很多人都忙着画各种各样的图标.这样很容易让那些新人们走错路,最后我想说的是icon不是全部,不要沉迷其中,要学的还有很 ...
- spring boot学习02【如何在spring boot项目中访问jsp】
1.配置application.properties文件 打开application.properties追加 spring.mvc.view.prefix=/WEB-ROOT/ spring.mvc ...
- zoj 2886 Look and Say
Look and Say Time Limit: 2 Seconds Memory Limit: 65536 KB The look and say sequence is defined ...
- 0元免费领《JAVA日志》教程,天啦噜!
天啦,老码疯了!辛辛苦苦,费心费力准备的<java日志实战及解析>教程真的不要钱了吗? 作为添物网的小编,每天看着老码为了给大家录制课程,加班加点的做课件,为了保证课程的质量,老码一遍又一 ...
- 【HTML/XML 6】XML文档的基本组成
导读:大致上,一个XML文档可以由三个部分组成,即声明区.定义区和文档主体区.在XML文档中,各个组成部分都包含特定的内容,有着不同的作用.本篇博客,通过分析上篇博客中的XML实例,来了解XML文档 ...
- Divide Groups(分组)(二分图染色)
题目链接 题目大意是说输入数字n 然后告诉你第i个人都认识谁? 让你把这些人分成两堆,使这每个堆里的人都互相认识. 做法:把不是互相认识的人建立一条边,则构建二分图,两堆的人肯定都互相认识,也就是说, ...
- 洛谷P1077 摆花
题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...
- [NOIP2001] 提高组 洛谷P1027 Car的旅行路线
题目描述 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于一个 矩形的四个顶点上,同一个城市中两个机场之间有一条笔直的高速铁路,第I个城市中高速铁路了的单 ...
- 蓝桥杯 算法训练 最短路 [ 最短路 bellman ]
传送门 算法训练 最短路 时间限制:1.0s 内存限制:256.0MB 锦囊1 锦囊2 锦囊3 问题描述 给定一个n个顶点,m条边的有向图(其中某些边权可能为负,但保证 ...
- WordPress 权限方案
每个主机和主机的情况可能有所差异,如下只是概括性地描述,并不一定适用于所有情况.它只适用于进行“常规设置”的情况(注:比如通过“suexec”方式来进行共享主机的,详情见下方) 通常,所有文件是由您的 ...