Rain on your Parade

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 4728    Accepted Submission(s): 1552

Problem Description

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.

 

Input

The input starts with a line containing a single integer, the number of test cases.
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.
 

Output

For each test case, write a line containing “Scenario #i:”, where i is the number of the test case starting at 1. Then, write a single line that contains the number of guests that can at most reach an umbrella before it starts to rain. Terminate every test case with a blank line.
 

Sample Input

2
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
 

Sample Output

Scenario #1:
2

Scenario #2:
2

 

Source

 
匈牙利算法 复杂度:V×E, 本题TLE
转换为网络流模型,跑dinic? 本题MLE
所以,只能用Hopcroft_Karp。复杂度:sqrt(V)×E
V为点数,E为边数。
//2017-08-26
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue> using namespace std; const int N = ;
const int M = ;
const int INF = 0x3f3f3f3f;
int head[N], tot;
struct Edge{
int to, next;
}edge[M]; void add_edge(int u, int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
} //xlink[i]表示左集合顶点i匹配的右集合的点,ylink[i]表示右集合顶点i匹配的左集合的点
int xlink[N], ylink[N];
//xlevel[i]表示左集合顶点i的所在层数,ylevel[i]表示右集合顶点i的所在层数
int xlevel[N], ylevel[N];
bool vis[N];
struct Hopcroft_Karp{
int dis, xn, yn;//xn表示左集合顶点个数,yn表示右集合顶点个数
void init(int _xn, int _yn){
tot = ;
xn = _xn;
yn = _yn;
memset(head, -, sizeof(head));
memset(xlink, -, sizeof(xlink));
memset(ylink, -, sizeof(ylink));
}
bool bfs(){
queue<int> que;
dis = INF;
memset(xlevel, -, sizeof(xlevel));
memset(ylevel, -, sizeof(ylevel));
for(int i = ; i < xn; i++)
if(xlink[i] == -){
que.push(i);
xlevel[i] = ;
}
while(!que.empty()){
int u = que.front();
que.pop();
if(xlevel[u] > dis)break;
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to;
if(ylevel[v] == -){
ylevel[v] = xlevel[u] + ;
if(ylink[v] == -)
dis = ylevel[v];
else{
xlevel[ylink[v]] = ylevel[v]+;
que.push(ylink[v]);
}
}
}
}
return dis != INF;
}
int dfs(int u){
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to;
if(!vis[v] && ylevel[v] == xlevel[u]+){
vis[v] = ;
if(ylink[v] != - && ylevel[v] == dis)
continue;
if(ylink[v] == - || dfs(ylink[v])){
xlink[u] = v;
ylink[v] = u;
return ;
}
}
}
return ;
}
//二分图最大匹配
//input:建好的二分图
//output:ans 最大匹配数
int max_match(){
int ans = ;
while(bfs()){
memset(vis, , sizeof(vis));
for(int i = ; i < xn; i++)
if(xlink[i] == -)
ans += dfs(i);
}
return ans;
}
}hk_match; int n, m, pour_time;
struct Guests{
int x, y, speed;
}guests[N]; struct Umbrella{
int x, y;
}umbrella[N]; bool getUmbrella(int i, int j){
return (guests[i].x-umbrella[j].x)*(guests[i].x-umbrella[j].x)
+ (guests[i].y-umbrella[j].y)*(guests[i].y-umbrella[j].y)
<= guests[i].speed*guests[i].speed*pour_time*pour_time;
} int main()
{
std::ios::sync_with_stdio(false);
//freopen("inputF.txt", "r", stdin);
int T, kase = ;
cin>>T;
while(T--){
cin>>pour_time>>m;
for(int i = ; i < m; i++)
cin>>guests[i].x>>guests[i].y>>guests[i].speed;
cin>>n;
for(int i = ; i < n; i++)
cin>>umbrella[i].x>>umbrella[i].y;
hk_match.init(m, n);
for(int i = ; i < m; i++)
for(int j = ; j < n; j++)
if(getUmbrella(i, j))
add_edge(i, j);
cout<<"Scenario #"<<++kase<<":"<<endl<<hk_match.max_match()<<endl<<endl;
} return ;
}

HDU2389(KB10-F 二分图最大匹配Hopcroft_Karp)的更多相关文章

  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] 2063 过山车(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio> ...

  3. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

  4. 二分图最大匹配:匈牙利算法的python实现

    二分图匹配是很常见的算法问题,一般用匈牙利算法解决二分图最大匹配问题,但是目前网上绝大多数都是C/C++实现版本,没有python版本,于是就用python实现了一下深度优先的匈牙利算法,本文使用的是 ...

  5. bzoj 1854: [Scoi2010]游戏 (并查集||二分图最大匹配)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1854 写法1: 二分图最大匹配 思路:  将武器的属性对武器编号建边,因为只有10000种 ...

  6. 二分图最大匹配|UOJ#78|匈牙利算法|边表|Elena

    #78. 二分图最大匹配 从前一个和谐的班级,有 nlnl 个是男生,有 nrnr 个是女生.编号分别为 1,…,nl1,…,nl 和 1,…,nr1,…,nr. 有若干个这样的条件:第 vv 个男生 ...

  7. HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  8. 【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix

    给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...

  9. 【bzoj2044】三维导弹拦截 dp+二分图最大匹配

    题目描述 n个物品,第i个位置有ai.bi.ci三种属性.每次可以选出满足$\ a_{p_i}<a_{p_{i+1}}\ ,\ b_{p_i}<b_{p_{i+1}}\ ,\ c_{p_i ...

随机推荐

  1. 深度学习:浅谈RNN、LSTM+Kreas实现与应用

    主要针对RNN与LSTM的结构及其原理进行详细的介绍,了解什么是RNN,RNN的1对N.N对1的结构,什么是LSTM,以及LSTM中的三门(input.ouput.forget),后续将利用深度学习框 ...

  2. PHP中正则表达式函数(Perl兼容)

    PHP为使用Perl兼容的正则表达式搜索字符串提供了7个函数,分别是preg_grep().preg_match().preg_match_all().preg_quote().preg_replac ...

  3. 【环境学习】ThinkPHP5 5.0.22/5.1.29 远程代码执行漏洞

    环境保留:2019.4.4-4.10 环境搭建: 这里我使用的是:vulhub vulhub目录结构:vulhub/thinkphp/5-rcess 测试地址(开放一段时间供大家学习):http:// ...

  4. 【ElasticSearch】:Windows下ElasticSearch+版本安装head

    概述 elasticsearch-head,之前插件plugin方式已废弃,现已改为nodejs的NPM安装,独立WEB服务方式. elasticsearch-head网址:https://githu ...

  5. flask框架--cookie,session

    今天我又给大家分享一下怎么用flask框架来实现像淘宝购物车一样存储数据,并且把存储的数据删除,这个方法可以用两个方法都可以做成,一个是cookie,另一个是session. session是依赖于c ...

  6. 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片)

    解决 将Python项目打包成EXE可执行文件(单文件,多文件,包含图片) 1.当我们写了一个Python的项目时,特别是一个GUI项目,我们特备希望它能成为一个在Windows系统可执行的EXE文件 ...

  7. 09-03 Java 抽象类

    抽象类的特点 /* 抽象类的概述: 动物不应该定义为具体的东西,而且动物中的吃,睡等也不应该是具体的. 我们把一个不是具体的功能称为抽象的功能,而一个类中如果有抽象的功能,该类必须是抽象类. 抽象类的 ...

  8. 课程一(Neural Networks and Deep Learning),第四周(Deep Neural Networks)—— 1.Practice Questions: Key concepts on Deep Neural Networks

    [解释] [解释] 比如算法中的learing rateα(学习率).iterations(梯度下降法循环的数量).L(隐藏层数目).n[l] (隐藏层单元数目).choice of activati ...

  9. godaddy 问题

    1. 域名被锁,打电话咨询后.说发送被锁的域名到: change@secureserver.net 去解锁.

  10. java+hibernate+mysql

    实体类News package org.mythsky.hibernatedemo; import javax.persistence.*; @Entity @Table(name="new ...