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 ...
随机推荐
- R语言常用操作
1 取整运算 在编程实现的时候有时会碰到对数值取整的需求,而取整的方式却多种多样,依赖于具体问题,不过在R中已经配备了种类齐全的相关函数,主要包括以下五种: floor():向下取整: ceiling ...
- window有哪些属性?
self:self代表自己,相当于window. parent:返回父窗口. top:返回顶层窗口,和parent作用一样. opener:窗口开启者. status:设置窗口状态栏的文本.
- Java的File.separator
一.File类 在Windows下的路径分隔符(\)和在Linux下的路径分隔符(/)是不一样的,当直接使用绝对路径时,跨平台会报No Such file or diretory异常. File中还有 ...
- Docker安装websphere(四)
在Docker容器里安装webshpere <!--前提:已经安装好了docker,能够正常使用.--> (1)docker安装websphere(需要账号和密码登录,不挂载数据卷) 获取 ...
- Linux 目录配置标准:FHS
目录 应放置内容 /bin 和/user/目录下的/bin/都是用来保存的系统命令 /sbin 和/user/目录下的/sbin是用来保存root的系统命令 /boot 这个目录主要放置开机所用的文件 ...
- VSTO:使用C#开发Excel、Word【6】
Office主互操作程序集(PIA)在了解如何构建Office解决方案之前,您需要更详细地了解在.NET中与Office对象模型通信的托管程序集.用于与Office通话的托管程序集称为Office主互 ...
- C++基础知识:异常处理
1.C++中的异常处理(1)C++ 中提供了 try和catch语句块对可能产生异常的代码进行分开处理 -try语句块处理正常逻辑 -catch语句块处理异常(2)C++ 语言中通过 throw语 ...
- 福大软工 · BETA 版冲刺前准备之拖鞋旅游队
拖鞋旅游队BETA 版冲刺前准备 前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10083834.html 本次作业:https://edu.c ...
- 手机号的 DES-ECB 加密/解密
前言:公司的手机号加密更换了加密方法,这次改成 DES-ECB 加密了 代码操作 # -*- coding:utf-8 -*- import base64 import json from Crypt ...
- 分析无线遥控器信号并制作Hack硬件进行攻击
无线遥控器(无线电遥控器)在我们生活中非常常见,应用于各种场景,方便着用户的使用.不过大多数还是用于安防方面的,比如: 遥控报警器.电动卷帘门.电动伸缩门.遥控电开关.无线遥控门铃…… 1.无线遥控器 ...