传送门:Rain on your Parade

题意:t个单位时间后开始下雨,给你N个访客的位置(一维坐标平面内)和他的移动速度,再给M个雨伞的位置,问在下雨前最多有多少人能够拿到雨伞(两个人不共用一把伞)。

分析:这题匈牙利算法撸不过,只好去学习Hopcroft-Carp算法,复杂度为O(sqrt(V)*E),该算法预先找好增广路径集,避免了许多没不要的匹配.

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 10010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
int dx[N],dy[N],matchx[N],matchy[N];
int vis[N],dis,n,m,t;
vector<int>g[N];
struct node
{
int x,y,z;
}s[N];
bool search_path()
{
queue<int>que;
dis=inf;
FILL(dx,-);FILL(dy,-);
for(int i=;i<=n;i++)
{
if(matchx[i]==-)
{
que.push(i);
dx[i]=;
}
}
while(!que.empty())
{
int u=que.front();
que.pop();
if(dx[u]>dis)break;
for(int i=,sz=g[u].size();i<sz;i++)
{
int v=g[u][i];
if(dy[v]==-)
{
dy[v]=dx[u]+;
if(matchy[v]==-)dis=dy[v];
else
{
dx[matchy[v]]=dy[v]+;
que.push(matchy[v]);
}
}
}
}
return dis!=inf;
}
int dfs(int u)
{
for(int i=,sz=g[u].size();i<sz;i++)
{
int v=g[u][i];
if(!vis[v]&&dy[v]==dx[u]+)
{
vis[v]=;
if(matchy[v]!=-&&dy[v]==dis)continue;
if(matchy[v]==-||dfs(matchy[v]))
{
matchy[v]=u;
matchx[u]=v;
return ;
}
}
}
return ;
}
int HK()
{
int res=;
FILL(matchx,-);FILL(matchy,-);
while(search_path())
{
FILL(vis,);
for(int i=;i<=n;i++)
if(matchx[i]==-&&dfs(i))res++;
}
return res;
}
bool judge(int a,int b,int x,int y,int z)
{
return (a-x)*(a-x)+(b-y)*(b-y)<=(z*t)*(z*t);
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&t,&n);
for(int i=;i<=n;i++)g[i].clear();
for(int i=;i<=n;i++)
scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].z);
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
for(int j=;j<=n;j++)
{
if(judge(x,y,s[j].x,s[j].y,s[j].z))
g[j].push_back(i);
}
}
int ans=HK();
printf("Scenario #%d:\n%d\n",cas++,ans);
puts("");
}
}

hdu2389(HK算法)的更多相关文章

  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-2389.rain on your parade(二分匹配HK算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  3. 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 every ...

  4. HDU2389:Rain on your Parade(二分图最大匹配+HK算法)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  5. LightOJ 1356 Prime Independence 二分图最大独立集,HK算法

    这个题唯一需要说的就是普通的匈牙利算法是O(nm)的,过不了 然后HK算法可以O(n^0.5m),这个算法可以每次找很多同样长度的最短增广路 分析见:http://www.hardbird.net/l ...

  6. HDU 2389 Rain on your Parade 最大匹配(模板题)【HK算法】

    <题目链接> 题目大意:有m个宾客,n把雨伞,预计时间t后将会下大雨,告诉你每个宾客的位置和速度,每把雨伞的位置,问你最多几个宾客能够拿到伞. 解题分析: 本题就是要我们求人与伞之间的最大 ...

  7. hdu 2389(二分图hk算法模板)

    Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Ot ...

  8. POJ1469 COURSES 【二分图最大匹配&#183;HK算法】

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17777   Accepted: 7007 Descript ...

  9. 【机器学习】HK算法(LMSE算法) LMS算法改进保证线性可分时均方误差标准能够找到线性可分的超平面

    1.其实HK算法思想很朴实,就是在最小均方误差准则下求得权矢量. 他相对于感知器算法的优点在于,他适用于线性可分和非线性可分得情况,对于线性可分的情况,给出最优权矢量,对于非线性可分得情况,能够判别出 ...

随机推荐

  1. addEventListener()及attachEvent()区别分析

    Javascript 的addEventListener()及attachEvent()区别分析 Mozilla中: addEventListener的使用方式: target.addEventLis ...

  2. webform中几个常用的控件

    一,简单控件 1,Lable——标签:在网页中呈现出来的时候会变成span标签 属性:Text——标签上的文字  BackColor,ForeColor——背景色,前景色 Font——字体 Bold- ...

  3. 【Tips】Endnote导入IEEE Xplore文献方法《转载》

    1. 在IEEE XPlore中点击“Download Citation”: 2. 选中“Citation & Abstract”和“EndNote,Procite,RefMan”两个选项: ...

  4. linux shell脚本:在脚本中实现读取键盘输入,根据输入判断下一步的分支

    echo please input “runbip” to run bip. variableName="null" while [ $variableName != " ...

  5. Spring Session - Spring Boot

    The completed guide can be found in the boot sample application. Updating Dependencies Before you us ...

  6. Python脚本:获取股票信息

    在水木上看到有人在问到想用python去获取股票的信息,sina finance上面的那些数据的是通过js控制的,会根据股票代码去获取实时信息然后根据用户友好的方式展示出来.首先,新浪的一个url让我 ...

  7. SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意  ...

  8. crm使用FetchXml聚合查询

    /* 创建者:菜刀居士的博客  * 创建日期:2014年07月08号  */ namespace Net.CRM.FetchXml {     using System;     using Micr ...

  9. 国际化之DateFormat、NumberFormat

    之所以在国际化中介绍DateFormat和NumberFormat这两个类,一是因为本身这两个类是地区敏感类,即可用传入Locale对象:二是因为这两个类具有不同的输出模式,而这些模式能在国际化的动态 ...

  10. eval 捕获错误

    eval 捕获错误: [root@dr-mysql01 ~]# cat t1.pl use DBI; my $dbUser='zabbix'; my $user="root"; m ...