HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)
Rain on your Parade
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 2154 Accepted Submission(s): 662
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
Hopcroft-Carp算法
测试下模板,还是很快的
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;
/* *******************************
* 二分图匹配(Hopcroft-Carp算法)
* 复杂度O(sqrt(n)*E)
* 邻接表存图,vector实现
* vector先初始化,然后假如边
* uN 为左端的顶点数,使用前赋值(点编号0开始)
*/
const int MAXN = ;
const int INF = 0x3f3f3f3f;
vector<int>G[MAXN];
int uN; 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;
} struct Point
{
int x,y,s;
void input1()
{
scanf("%d%d%d",&x,&y,&s);
}
void input2()
{
scanf("%d%d",&x,&y);
}
};
int dis2(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
Point p1[MAXN],p2[MAXN]; int main()
{
int T;
int t;
int iCase = ;
int n,m;
scanf("%d",&T);
while(T--)
{
iCase++;
scanf("%d",&t);
scanf("%d",&n);
for(int i = ;i < n;i++)
p1[i].input1();
scanf("%d",&m);
for(int i = ;i < m;i++)
p2[i].input2();
for(int i = ;i < n;i++)
G[i].clear();
uN = n;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(dis2(p1[i],p2[j]) <= p1[i].s*p1[i].s*t*t)
G[i].push_back(j);
printf("Scenario #%d:\n",iCase);
printf("%d\n\n",MaxMatch());
}
return ;
}
HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)的更多相关文章
- HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配)
HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配) Description You're giving a ...
- Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)
题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...
- HDU 2389 ——Rain on your Parade——————【Hopcroft-Karp求最大匹配、sqrt(n)*e复杂度】
Rain on your Parade Time Limit:3000MS Memory Limit:165535KB 64bit IO Format:%I64d & %I64 ...
- 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 2389 Rain on your Parade
大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再 time 时间内移动到不同的雨伞处(不允许两个人共用一把伞). 输入数据: 第一行是一个T代表T组测试数据 ...
- HDU 2389 Rain on your Parade 最大匹配(模板题)【HK算法】
<题目链接> 题目大意:有m个宾客,n把雨伞,预计时间t后将会下大雨,告诉你每个宾客的位置和速度,每把雨伞的位置,问你最多几个宾客能够拿到伞. 解题分析: 本题就是要我们求人与伞之间的最大 ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2389 Rain on your Parade
HK.... Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K ...
- HDU 6178 Monkeys(树上的二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过 ...
随机推荐
- linux驱动基础系列--Linux下Spi接口Wifi驱动分析
前言 本文纯粹的纸上谈兵,我并未在实际开发过程中遇到需要编写或调试这类驱动的时候,本文仅仅是根据源码分析后的记录!基于内核版本:2.6.35.6 .主要是想对spi接口的wifi驱动框架有一个整体的把 ...
- Linux 入门记录:七、fdisk 分区工具
一.fdisk分区工具 fdisk 是来自 IBM 的老牌分区工具,支持绝大多数操作系统,几乎所有的 Linux 发行版都装有 fdisk,包括在 Linux 的 resuce 模式下依然能够使用. ...
- linux arm的存储分布那些事之一
转自:http://blog.csdn.net/xiaojsj111/article/details/11724081 linux arm 内存分布总览 上图是linux的arm的虚拟地址分布 ...
- 64_l6
lightdm-qt5-devel-1.22.0-1.fc26.i686.rpm 19-May-2017 11:11 22854 lightdm-qt5-devel-1.22.0-1.fc26.x86 ...
- Perl中文件读取操作
Perl中文件读取操作 http://blog.csdn.net/yangxuan12580/article/details/51506216
- 使用OC swift 截取路径中的最后的文件名
使用 OC swift 截取路径中的最后的文件名 如何截取下面路径中最后的文件名 AppDelegate.swift /Users/XXX/Desktop/Swift/swift02/code/02- ...
- [hadoop][会装]hadoop ha模式安装
1.简介 2.X版本后namenode支持了HA特性,使得整个文件系统的可用性更加增强. 2.安装前提 zookeeper集群,zookeeper的安装参考[hadoop][会装]zookeeper安 ...
- Leetcode 之Balanced Binary Tree(49)
用递归的方式来做,左右两棵子树的高度差不超过1.分成两部分,一部分递归得到树的高度,一部分递归检查左右子树是否是平衡二叉树. int getHeight(TreeNode *root) { ; ; } ...
- matlab实用命令
实用命令 打点测时 在需要测量的开始部分标记: tic 在需要测量的结束部分标记: toc 记录程序从tic到toc运行所花费的时间 Image 翻转 fliplr(x) //左右翻转 flipud( ...
- 把web项目部署到tomcat上
首先在服务器搭建JDK环境:https://www.cnblogs.com/lb809663396/p/5855877.html 然后把tomcat文件包复制到服务器上,访问http://localh ...