hdu 2389(二分图hk算法模板)
Rain on your Parade
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 3675 Accepted Submission(s): 1187
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.
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.
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.
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
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int INF = ;
struct Node
{
int x,y,v;
} p[N],ub[N];
int graph[N][N];
int n,m,dist;
bool vis[N];
int cx[N],cy[N],dx[N],dy[N];
int dis(Node a,Node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool searchpath()
{
queue<int> Q;
dist=INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i=;i<=n;i++)
{
if(cx[i]==-)
{
Q.push(i);
dx[i]=;
}
}
while(!Q.empty())
{
int u=Q.front();
Q.pop();
if(dx[u]>dist) break;
for(int v=;v<=n;v++)
{
if(graph[u][v]&&dy[v]==-)
{
dy[v]=dx[u]+;
if(cy[v]==-) dist=dy[v];
else
{
dx[cy[v]]=dy[v]+;
Q.push(cy[v]);
}
}
}
}
return dist!=INF;
}
int findpath(int u)
{
for(int v=;v<=m;v++)
{
if(!vis[v]&&graph[u][v]&&dy[v]==dx[u]+)
{
vis[v]=;
if(cy[v]!=-&&dy[v]==dist)
{
continue;
}
if(cy[v]==-||findpath(cy[v]))
{
cy[v]=u;cx[u]=v;
return ;
}
}
}
return ;
}
void 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);
}
}
}
printf("%d\n\n",res);;
}
int main()
{
int tcase;
scanf("%d",&tcase);
int t = ;
while(tcase--)
{
memset(graph,,sizeof(graph));
int time;
scanf("%d",&time);
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int v;
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].v);
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&ub[i].x,&ub[i].y);
}
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(dis(p[i],ub[j])<=p[i].v*p[i].v*time*time)
{
graph[i][j] = ;
}
}
}
printf("Scenario #%d:\n",t++);
MaxMatch();
}
return ;
}
hdu 2389(二分图hk算法模板)的更多相关文章
- HDU 1083 - Courses - [匈牙利算法模板题]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...
- HDU 2586 ( LCA/tarjan算法模板)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:n个村庄构成一棵无根树,q次询问,求任意两个村庄之间的最短距离 思路:求出两个村庄的LCA,d ...
- HDU 2255 二分图最佳匹配 模板题
题目大意: 给定每一个人能支付的房子价值,每个人最多且必须拥有一套房子,问最后分配房子可得到的最大收益 抄了个别人的KM模板,就这样了... #include <cstdio> #incl ...
- POJ1325机器重启次数——二分图匈牙利算法模板
题目:http://poj.org/problem?id=1325 求最小点覆盖.输出最大匹配数就行,结果略复杂地弄了. 注意由题可知 可以直接把与0有关的边删掉.不过亲测不删0而计数时不计0就会WA ...
- HK算法模板+小优化(跑的快一点点)
HUST 2604 #include <iostream> #include <cstdlib> #include <cstdio> #include <cs ...
- HDU 2389 Rain on your Parade 最大匹配(模板题)【HK算法】
<题目链接> 题目大意:有m个宾客,n把雨伞,预计时间t后将会下大雨,告诉你每个宾客的位置和速度,每把雨伞的位置,问你最多几个宾客能够拿到伞. 解题分析: 本题就是要我们求人与伞之间的最大 ...
- HDU 5727 - Necklace - [全排列+二分图匹配][Hopcroft-Karp算法模板]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. ...
- 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 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
随机推荐
- Communications link failure
针对数据库Communications link failure的错误,可以理解为有两种策略解决: 策略1(推荐): 数据池配置 <property name="minEvic ...
- 【单调队列】【P1776】宝物筛选
传送门 Description 终于,破解了千年的难题.小FF找到了王室的宝物室,里面堆满了无数价值连城的宝物--这下小FF可发财了,嘎嘎.但是这里的宝物实在是太多了,小FF的采集车似乎装不下那么多宝 ...
- 从MYSQL数据库查出指定格式的日期
1.用SQL语言控制: 格式如下: select DATE_FORMAT(t.startTime,"%Y-%m-%d %H:%i") AS startTime, DATE_FORM ...
- 2017-7-18-每日博客-关于Linux下的鲜为人知的10条命令.doc
这篇文章的目的是介绍一些少有人知的Linux命令,它们一定会高效地帮你管理你的桌面/服务器. 1. sudo !!命令 没有特定输入sudo命令而运行,将给出没有权限的错误.那么,你不需要重写整个命令 ...
- Codeforces Round #337 (Div. 2)B
B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 使用springcloud的feign调用服务时出现的错误:关于实体转换成json错误的介绍
http://blog.csdn.net/java_huashan/article/details/46428971 原因:实体中没有添加无参的构造函数 fastjson的解释: http://www ...
- bzoj 3580 冒泡排序 乱搞+思维
冒泡排序 Time Limit: 15 Sec Memory Limit: 256 MBSubmit: 243 Solved: 108[Submit][Status][Discuss] Descr ...
- C#学习之泛型继承和静态成员
想要理解这里有必要先将泛型类学习充分.这里讲解的是泛型类继承类的类型和静态成员. 在前面C#学习之泛型中,创建的LinkList<T>类实现了IEnumerable<T>接口. ...
- Leetcode 200. 岛屿的个数(扩展)
1.题目描述 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 ...
- Foxmail安装和登录
Foxmail安装和登录... ============================== 下载Foxmail客户端:http://www.foxmail.com/ ================ ...