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 ...
随机推荐
- 软银开放Pepper开发,给机器人写安卓App是怎样一种体验?
日本软银推出的Pepper智能机器人 新浪科技讯 北京时间5月19日下午消息,谷歌Android移动操作系统的触角正在不断扩大,从今天开始,开发者可以为日本电信公司软银的Pepper人形机器人设计An ...
- 如何用好 github 中的 watch、star、fork
http://www.jianshu.com/p/6c366b53ea41 https://www.zhihu.com/question/20431718 在每个 github 项目的右上角,都有三个 ...
- UIView的autoresizingMask属性研究
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum ...
- Qt -------- 容器类
QVector(数组).QLinkedList(链表).QMap(映射表).QHash(哈希表).QQueue(队列) QHash遍历举例: 法1: QThread& ThreadHandle ...
- eclipse中编写代码时如何自动提示变量名?
打开 Eclipse -> Window -> Perferences -> Java -> Editor -> Content Assist,在右边最下面一栏找到 a ...
- nodejs+react构建仿知乎的小Demo
一.命令行进入指定项目文件夹 二.相关命令安装环境和项目工具 npm init npm install react -- save npm install -g gulp npm install -- ...
- java有关Time类型数据的接收和转换
一:前言 有关Time的时间其实很少有用到.但是用到就很纠结了,转换和保存,都是烦人的事情,我自己就在这上面吃过一个亏,所以就加载下来吧! 二:内容 (1):被坑的地方 实体类 import java ...
- [洛谷P2704] [NOI2001]炮兵阵地
洛谷题目链接:[NOI2001]炮兵阵地 题目描述 司令部的将军们打算在NM的网格地图上部署他们的炮兵部队.一个NM的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示), ...
- html 制作静态页面新知识
1.在区块线边框添加一条水平线 例如:<div style:"height :300px;width:800px;border-bottom: solid 1px orange ;& ...
- 【BZOJ4868】期末考试 [三分][贪心]
期末考试 Time Limit: 20 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description Input Output Samp ...