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.

虽然也是二分图匹配,但是需要用HK算法,匈牙利算法会超时

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
const int MAXN=;//最大点数
const int INF=0x3f3f3f3f;//距离初始值
int Map[MAXN][MAXN];//二分图
int cx[MAXN];//cx[i]表示左集合i顶点所匹配的右集合的顶点序号
int cy[MAXN];//cy[i]表示右集合i顶点所匹配的左集合的顶点序号
int n,m,dis;
int dx[MAXN],dy[MAXN];
bool vis[MAXN];
int xp[],yp[],s[];
int xu[],yu[]; bool searchpath(){
queue<int>Q;
dis=INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i=;i<=n;++i){
//cx[i]表示左集合i顶点所匹配的右集合的顶点序号
if(cx[i]==-){
//将未遍历的节点入队并初始化次节点距离为0
Q.push(i);
dx[i]=;
}
}
//广度搜索增广路径
while(!Q.empty()){
int u=Q.front();
Q.pop();
if(dx[u]>dis)break;
//取右侧节点
for(int i=;i<=m;++i){
//右侧节点的增广路径的距离
if(Map[u][i]&&dy[i]==-){
dy[i]=dx[u]+;//v对应的距离为u对应距离加1
if(cy[i]==-)dis=dy[i];
else{
dx[cy[i]]=dy[i]+;
Q.push(cy[i]);
}
}
}
}
return dis!=INF;
} //寻找路径深度搜索
int findpath(int s){
for(int i=;i<=m;++i){
//如果该点没有被遍历过并且距离为上一节点+1
if(!vis[i]&&Map[s][i]&&dy[i]==dx[s]+){
//对该点染色
vis[i]=;
if(cy[i]!=-&&dy[i]==dis)continue;
if(cy[i]==-||findpath(cy[i])){
cy[i]=s;cx[s]=i;
return ;
}
}
}
return ;
} //得到最大匹配的数目
int MaxMatch(){
int res=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
while(searchpath()){
memset(vis,,sizeof(vis));
for(int i=;i<=n;++i){
if(cx[i]==-)res+=findpath(i);
}
}
return res;
} int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;++q){
memset(Map,,sizeof(Map));
int t;
scanf("%d",&t);
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d%d",&xp[i],&yp[i],&s[i]);
}
scanf("%d",&m);
for(int i=;i<=m;++i){
scanf("%d%d",&xu[i],&yu[i]);
}
for(int i=;i<=n;++i){
for(int j=;j<=m;++j){
if((xp[i]-xu[j])*(ll)(xp[i]-xu[j])+(yp[i]-yu[j])*(ll)(yp[i]-yu[j])<=t*(ll)t*s[i]*s[i]){
Map[i][j]=;
}
}
}
printf("Scenario #%d:\n%d\n\n",q,MaxMatch());
}
return ;
}

hdu2389 Rain on your Parade 二分图匹配--HK算法的更多相关文章

  1. HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法

    题目链接:https://vjudge.net/problem/HDU-2389 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)  ...

  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. Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)

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

  4. 二分图匹配-HK算法

    先把代码贴上,其他南京回来再补了.. #include <cstdio> #include <cstdlib> #include <cstring> #includ ...

  5. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)

    The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...

  7. 训练指南 UVALive - 4043(二分图匹配 + KM算法)

    layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...

  8. 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 ...

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

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

随机推荐

  1. Daily record-August

    August11. A guide dog can guide a blind person. 导盲犬能给盲人引路.2. A guide dog is a dog especially trained ...

  2. learning at command AT+CEREG

    AT command AT+CEREG [Purpose]        Learning how to query the network registration status   [Eeviro ...

  3. python之路 ---计算机硬件基础

    计算机(computer)俗称电脑,是现代一种用于高速计算的电子计算机器,可以进行数值计算,又可以进行逻辑计算,还具有存储记忆功能.是能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备.一个 ...

  4. 前端之Bootstrap框架

    一.Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序而设计的一套前端工具包. 它支持响应式布局, ...

  5. 数学软件Matlab的使用感受

    在我一年前的暑假,我们的小学期学习了MATLAB软件.MATLAB是一款数学软件,可以用于算法计算.数据可视化.数据分析以及数据计算. 我们主要学习了MATLAB关于数学上的经常用的一些用法和算法,M ...

  6. 50个常用的Linux命令

    1.tar tar -xvf archive_name.tar  解压文件 tar -cvf archive_name.tar file 把文件file压缩成archive_name.tar tar ...

  7. 什么是Java优先级队列(Priority Queue)?

    PriorityQueue是一个基于优先级堆的无界队列.它的元素是按照自然顺序排序的.在创建元素的时候,我们给它一个一个负责排序的比较器.PriorityQueue不允许null值,因为 它们没有自然 ...

  8. SQL-15 查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列

    题目描述 查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列CREATE TABLE `employees` (`emp_no ...

  9. mybatis-generator没有自动生成代码和Junit测试controller

    本来mybatis的generator想要自动生成增删改的,但是到后来语句就两个select,原因是数据中没有给字段加primary,就不会有删改增. 以及Controller的Junit测试 先导入 ...

  10. MySQL:用户管理

    用户管理部分 一.数据库不安全因素 非授权用户对数据库的恶意存取和破坏: 数据库中重要或敏感的数据被泄露: 安全环境的脆弱性: 二.数据库安全的常用方法 用户标识和鉴别[使用口令鉴别]::该方法由系统 ...