链接:

https://vjudge.net/problem/HDU-2389

题意:

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.

思路:

二分图最大匹配,匈牙利算法超时。改用hopcroft-karp算法。

吧能在时间内跑到的伞加到人的配对上,hopcroft-karp算法还不是太懂。

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN = 3e3+10;
const int INF = 1<<30; struct Node
{
double x, y;
};
Node P[MAXN], U[MAXN];
vector<int> G[MAXN];
double Speed[MAXN];
int Link_l[MAXN], Vis[MAXN];
int Link_r[MAXN];
int Dis_x[MAXN], Dis_y[MAXN];
int n, m;
int dis; double GetLen(Node a, Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} bool Search()
{
memset(Dis_x, -1, sizeof(Dis_x));
memset(Dis_y, -1, sizeof(Dis_y));
dis = INF;
queue<int> que;
for (int i = 1;i <= m;i++)
{
if (Link_r[i] == -1)
que.emplace(i);
Dis_x[i] = 0;
}
while (!que.empty())
{
int u = que.front();
que.pop();
if (Dis_x[u] > dis)
break;
for (int i = 0;i < G[u].size();i++)
{
int node = G[u][i];
if (Dis_y[node] == -1)
{
Dis_y[node] = Dis_x[u]+1;
if (Link_l[node] == -1)
dis = Dis_y[node];
else
{
Dis_x[Link_l[node]] = Dis_y[node]+1;
que.push(Link_l[node]);
}
}
}
}
return dis != INF;
} bool Dfs(int x)
{
for (int i = 0;i < G[x].size();i++)
{
int node = G[x][i];
if (Vis[node] || Dis_y[node] != Dis_x[x]+1)
continue;
Vis[node] = 1;
if (Link_l[node] != -1 && Dis_y[node] == dis)
continue;
if (Link_l[node] == -1 || Dfs(Link_l[node]))
{
Link_l[node] = x;
Link_r[x] = node;
return true;
}
}
return false;
} int Solve()
{
memset(Link_l, -1, sizeof(Link_l));
memset(Link_r, -1, sizeof(Link_r));
int cnt = 0;
while (Search())
{
memset(Vis, 0, sizeof(Vis));
for (int i = 1;i <= m;i++)
{
if (Link_r[i] == -1 && Dfs(i))
cnt++;
}
}
return cnt;
} int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
int time;
scanf("%d", &time);
scanf("%d", &m);
for (int i = 1;i <= m;i++)
G[i].clear();
for (int i = 1;i <= m;i++)
scanf("%lf%lf%lf", &P[i].x, &P[i].y, &Speed[i]);
scanf("%d", &n);
for (int i = 1;i <= n;i++)
scanf("%lf%lf", &U[i].x, &U[i].y);
for (int i = 1;i <= m;i++)
{
for (int j = 1;j <= n;j++)
{
double len = GetLen(P[i], U[j]);
if (len/Speed[i] <= time)
G[i].push_back(j);
}
}
int sum = Solve();
printf("Scenario #%d:\n%d\n\n", ++cnt, sum);
} return 0;
}

HDU-2389-Rain on your Parade (最大匹配,kopcroft-karp)的更多相关文章

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

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

  2. 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 ...

  3. HDU 2389 ——Rain on your Parade——————【Hopcroft-Karp求最大匹配、sqrt(n)*e复杂度】

    Rain on your Parade Time Limit:3000MS     Memory Limit:165535KB     64bit IO Format:%I64d & %I64 ...

  4. HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)

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

  5. HDU 2389 Rain on your Parade

    大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再 time 时间内移动到不同的雨伞处(不允许两个人共用一把伞).   输入数据: 第一行是一个T代表T组测试数据 ...

  6. Hdu 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)

    题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...

  7. HDOJ 2389 Rain on your Parade

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

  8. 【HDOJ】2389 Rain on your Parade

    读题显然是二分图匹配,看成guest与umbrella的匹配.匈牙利果断TLE了,其实时间卡的相当紧.HK过的,750ms. /* 2389 */ #include <iostream> ...

  9. HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法

    题目链接:https://vjudge.net/problem/HDU-2389 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)  ...

  10. Hdu2389 Rain on your Parade (HK二分图最大匹配)

    Rain on your Parade Problem Description You’re giving a party in the garden of your villa by the sea ...

随机推荐

  1. 精通CSS:高级Web标准解决方案(第二版) 不明白的地方

    P47 在图3-14中,当把框1向左浮动时,它脱离文档流并且向左移动,直到它的左边缘碰到包含框的左边缘.因为它不在处于文档流中,所以它不占据空间,实际上覆盖住了框2,使框2从视图中消失. 我的疑问是, ...

  2. 原生dapper中新增用户后根据用户id,在用户角色表中添加关联数据,事务处理

    var result = 0; var userId = 0; using (var db = _Sql.Connection) using (var tran =db.BeginTransactio ...

  3. java:struts框架5(Converter,Validation,Tags(Object-Graph Navigation Language))

    1.Converter: struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTY ...

  4. Flume采集日志

    角色 Source 数据来源 (exec, kafka, http…)Channel 数据通道 (memory,file,jdbc)Sink 数据目的地 (kafka,hdfs,es…) Agent ...

  5. pip install dal 失败问题

    这个问题是我在看一本<Django企业开发实战>运行其中一个项目时遇到的  作为一个自学的python 这种问题挺头疼的 这不是代码逻辑的问题 没法像Debug 一样去找问题 我们能依据的 ...

  6. python 正则sub的使用

     self.content = re.sub(r'>|<',lambda x: '&gt' if x.group()[0] == '>' else '&lt' , s ...

  7. 【转帖】国产x86处理器KX-6000发布

    国产最先进x86处理器KX-6000发布:8核3.0GHz 力压酷睿i5处理器 https://www.cnbeta.com/articles/tech/858981.htm 全网所有的网页都写错了 ...

  8. Tarjan水题系列(5):最大半连通子图 [ZJOI2007 luogu P2272]

    题目 大意: 缩点后转为求最长链的长度和最长链的个数 思路: 看懂题就会做系列 长度和个数都可以拓扑排序后DP求得 毕竟是2007年的题 代码: 如下 #include <cstdio> ...

  9. 匿名函数lambda和map函数

    一.map函数,实现迭代操作 map(f1,x) f1为函数的名称(不加括号),x为map的参数,示例如下: def add(a): return a+10 print map(add,[1,2,3] ...

  10. Git-版本控制 (二)

    昨天我们成功安装了Git,并且成功配置了环境变量~如果想看之前步骤的童鞋,请戳这里Git-版本控制(一) 今天我们要做的事情是:创建版本库.  (觉得非高大尚的童鞋举个爪子 = . =) en~~~~ ...