传送门: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. hdu1104 Remainder bfs找算式是否有解……

    须要注意的是,进行模运算剪枝-- #include<iostream> #include<queue> #include<cstdlib> #include< ...

  2. 支付宝打造公共账号业务网关, RSA密钥对生成

    作者: 玉龙      版权全部,同意转载. 请注明出处(创建金融_玉龙  http://www.weibo.com/u/1872245125) 原文地址: http://blog.csdn.net/ ...

  3. QNX 线程 调度策略 优先级 时钟频率 同步

    /* * barrier1.c */ #include <stdio.h>#include <unistd.h>#include <stdlib.h>#includ ...

  4. struts2 <s:iterator/>怎样取得循环的索引

    <s:iterator value="list" id="user" status="L"> <s:property va ...

  5. Codeforces Round #270--B. Design Tutorial: Learn from Life

    Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...

  6. listview——显示窗体

    listview——是用来显示的控件 一,属性 view:(显示的视图)LargeIcon——大图标:SmallIcon——小图标:Details——详细:List——列表:TItle——平铺 Sma ...

  7. ASP.NET - 多级分类

    表结构: 表数据: 最终效果: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehin ...

  8. ASP.NET - 上传图片方法(单张)

    /// <summary> /// 上传图片 /// </summary> /// <param name="fileupload">上传的控件 ...

  9. 通过程序预览Office文档

    我承认,标题是夸大了,就是为了吸引注意力.这里只有Word文档和Excel文档的预览代码. Word://此部分来源:http://princed.mblogger.cn/posts/11885.as ...

  10. Oracle左连接、右连接示例

    建表: create table a ( id ), name ) ); create table b ( name ), age ) ); create table c ( name ), dept ...