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 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算法的更多相关文章
- HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法
题目链接:https://vjudge.net/problem/HDU-2389 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) ...
- 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 ...
- Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)
题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...
- 二分图匹配-HK算法
先把代码贴上,其他南京回来再补了.. #include <cstdio> #include <cstdlib> #include <cstring> #includ ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)
The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...
- 训练指南 UVALive - 4043(二分图匹配 + KM算法)
layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...
- 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 ...
- HDU2389:Rain on your Parade(二分图最大匹配+HK算法)
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
随机推荐
- shell 基本概述
SHELL的概念 SHELL是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序, 用户可以用shell来启动,挂起,停止甚至是编写一些程序. Shell还是 ...
- Win10系列:VC++调用自定义组件2
(2)C#调用WinRT组件 在解决方案资源管理器中右键点击解决方案图标,选择添加一个Visual C#的Windows应用商店的空白应用程序项目,并命名为FileCS.接着右键点击FileCS项目的 ...
- 用老毛桃U盘安装:[3]Ghost版Win7系统
用老毛桃自动安装Ghost版Win7的步骤: 1,到网上先下载Ghost版Win7映像文件到硬盘,我放到的是U盘,盘符为Z,如果你愿意,可直接放到硬盘即可,放到硬盘安装速度会快一点. 2,把制作好的老 ...
- Annotation方式配置AOP
package com.xk.spring.kp04_aop.aop.s02_annotation; public interface IStudentService { public void sa ...
- nginx启用php
1. php下载https://secure.php.net/downloads.php搜索china镜像站点,从这里下载http://cn2.php.net/get/php-7.2.3.tar.gz ...
- weblogic连接池过小导致TPS呈周期性跳坑现象
利用晚上时间跑个12小时稳定性,第二天发现TPS曲线图成了这个样子. 排查步骤: 1.观察TPS图发现,几乎每两个小时TPS掉一次坑,是周期性的,而且TPS有掉到0的现象.LR上也有失败的交易,猜想是 ...
- SQL-5查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工
输出描述: 题目描述 查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工CREATE TABLE `dept_emp` (`emp_ ...
- Excel日常操作
1.固定表头 视图+冻结窗口+选择 2.下拉列表 数据+数据验证+序列+来源 筛选值也可是函数,函数值区间可以选择,然后隐藏该列数据即可 使用函数: 如果需要函数的值其他列也使用类似函数则拖动同样格式 ...
- Activity中通过标签获取当前Fragment
初始化完成之后才有数据,否则获取不到 String tag = "android:switcher:"+viewPager.getId()+":"+viewPa ...
- SharePoint Framework 在Visual Studio Code中调试你的本地解决方案
博客地址:http://blog.csdn.net/FoxDave Visual Studio Code不知道大家都有没有,界面清爽,编辑快速,是一个非常好的前端开发工具.本文介绍如何使用Goog ...