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.

Input

The input starts with a line containing a single integer, the number of test cases. 
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 <= s i <= 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. 

Output

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

Sample Input

2
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

Sample Output

Scenario #1:
2Scenario #2:
2

题解:

题意:

有一堆人在开party,然后t时间之后会下雨,有n个人,给出每个人的坐标和速度,然后又m把伞,给出伞坐标,问在下雨之前最多有几人能拿到伞(一人一把)

思路:

人匹配伞,一开始就用匈牙利算法搞了一遍,匈牙利算法时间复杂度是点数n乘上边数m,点有3000个,边最多有3000x3000个,乘起来毫无疑问会TLE。。。然后我就TLE了,搜了下题解原来是用HK算法搞,然后我就照着别人的模板根据自己的理解打了一遍。。我发现了如果这题用int处理而不是开根号算距离,用的时间是原来的1/4左右。。。学到了,还有就是静态数组处理会比动态处理快一些,这里用的是静态的邻接表写法的HK算法模板题

然后我看的大佬这题的博客:http://www.cnblogs.com/kuangbin/p/3224091.html

然后赋上他的HK算法邻接矩阵的模板:http://www.cnblogs.com/kuangbin/archive/2011/08/12/2135898.html

他的动态写法用时400多ms,我的静态的用时200多ms。。算是改进吧

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<deque>
#define M (t[k].l+t[k].r)/2
#define lson k*2
#define rson k*2+1
#define ll long long
#define INF 100861111;
using namespace std;
const int maxn=3005;
struct peo//存人的情况
{int x,y;int speed;
}a[maxn];
struct umb//存伞的情况
{int x,y;
}b[maxn];
int getdis(peo a,umb b)//获得距离的平方
{return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int p[maxn][maxn];//存第i个人可以取哪几把伞
int num[maxn];//存第i个人可以取多少伞
int usedx[maxn];//下面的都是用于HK算法的。。目前只写了一题还不太理解作用,照打了一遍
int usedy[maxn];
int dx[maxn],dy[maxn];
int vis[maxn],n,m;
int dis;//我也不知道有什么用,大佬也没讲
int find(int u)//相当于匈牙利算法的改进
{int i;for(i=0;i<num[u];i++){int v=p[u][i];if(!vis[v]&&dy[v]==dx[u]+1){vis[v]=1;if(usedy[v]!=-1&&dy[v]==dis)continue;if(usedy[v]==-1||find(usedy[v])){usedy[v]=u;usedx[u]=v;return 1;}}}return 0;
}
int searchp()//不知道怎么用,套模板。。
{queue<int>q;dis=INF;memset(dx,-1,sizeof(dx));memset(dy,-1,sizeof(dy));for(int i=1;i<=n;i++){if(usedx[i]==-1){q.push(i);dx[i]=0;}}while(!q.empty()){int u=q.front();q.pop();if(dx[u]>dis)break;for(int i=0;i<num[u];i++){int v=p[u][i];if(dy[v]==-1){dy[v]=dx[u]+1;if(usedy[v]==-1)dis=dy[v];else{dx[usedy[v]]=dy[v]+1;q.push(usedy[v]);}}}}return dis!=INF;
}
int hk()//hk算法
{int res=0,i;memset(usedx,-1,sizeof(usedx));memset(usedy,-1,sizeof(usedy));while(searchp()){memset(vis,0,sizeof(vis));for(i=1;i<=n;i++){if(usedx[i]==-1&&find(i))res++;}}return res;
}
int main()
{int i,j,test,cas;int t;scanf("%d",&test);for(cas=1;cas<=test;cas++){scanf("%d",&t);scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].speed);scanf("%d",&m);for(i=1;i<=m;i++)scanf("%d%d",&b[i].x,&b[i].y);memset(num,0,sizeof(num));for(i=1;i<=n;i++){for(j=1;j<=m;j++){if(getdis(a[i],b[j])<=a[i].speed*a[i].speed*t*t)//这里用int处理很快{p[i][num[i]]=j;num[i]++;}}}printf("Scenario #%d:\n",cas);printf("%d\n\n",hk());}return 0;
}

HDU 2389 Rain on your Parade(二分匹配+Hopcroft-Carp算法模板题)相关推荐

  1. HDU 2389 Rain on your Parade (二分图匹配)

    题意:天马上就要下雨了,然后有n个人,m把伞,然后分别给出人的坐标和他们跑的速度,以及伞的坐标,然后问在t时间内,最多能有多少人拿到伞. 题解:二分图匹配 之前做过一道类似的题目,是用最大流做的,但这 ...

  2. HDU - 2389 Rain on your Parade(Hopcroft-Krap算法求二分图最大匹配)

    题目链接:点击查看 题目大意:给出n个人和m个雨伞,t分钟后就要下雨了,现在给出每个人的坐标和速度,以及雨伞所在的坐标,每个雨伞只能容纳一个人,题目问最多有多少个人能不被淋到 题目分析:二分图最大匹配 ...

  3. Hdu 2389 Rain on your Parade

    大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再tmin内移动到不同的雨伞处(不允许两个人共用一把伞). 思路:很容易可以看出,这是一个二分图模型,雨伞和人一一 ...

  4. HDUOJ 2389 Rain on your Parade

    HDUOJ 2389 Rain on your Parade 题目链接 Problem Description You're giving a party in the garden of your ...

  5. HDU - 3081 Marriage Match II 【二分匹配】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...

  6. HDU 4685 Prince and Princess(二分匹配加点建图+强连通分量)

    题目链接 Problem Description There are n princes and m princesses. Princess can marry any prince. But pr ...

  7. HDU——hdu2389 Rain on your Parade

    hdu2389 Rain on your Parade 题解 1.构二分图. 2.匈牙利算法超时(O(VE)) 3.用Hopcroft-Carp算法(O(sqrt(V)E)) 算法讲解 算法模板 AC ...

  8. HDU 6178 Monkeys(树上的二分匹配+fread)

    题目地址 题意:你有n个节点,n-1条边构成一棵树,有m个猴子,猴子要在节点上,并且每个猴子至少要和另一只猴子有边相连,求最多需要多少条边 思路:最好的应该是猴子都是两两匹配的,因为每2个猴子相连的话 ...

  9. hdu 1045Fire Net (建图 、二分匹配)

    题意:需要求最大的放置炮台数(每个炮台都不能在其他炮台攻击范围内). 炮台攻击范围是:该炮台所在的行和列,但是'X'可以阻挡炮台攻击. 思路:二分匹配必须要有两个互不关联的集合,所以可以将行和列看做两 ...

最新文章

  1. js函数语法:ASCII 码的相互转换,字符串操作,数学计算
  2. 在“内卷”、“红海”的2020 年,开垦计算机视觉领域的知识荒原:BatchNorm
  3. jsp自定义标签学习
  4. python安装psycopg2
  5. Android应用程序消息处理机制(Looper、Handler)分析(1)
  6. 微软商店安装包_搞定你的数学问题:微软发布新APP可以手写或扫描数学题进行解答...
  7. 虚拟主机搭建微信公众号服务器,建web服务器同时如何搭建虚拟主机?方法有几种?...
  8. java servlet 配置_servlet与javabean配置
  9. 更改TFS项目中的SharePoint网站端口
  10. Codeforces Round #436 (Div. 2)
  11. POJ 1328 —— 贪心专题【区间贪心问题】
  12. 深入理解JVM虚拟机读书笔记——运行时数据区
  13. 95后阿里P7晒出工资单:狠补了这个,真香…
  14. python学习5(input函数)
  15. 怎么选择合适的机柜?网络机柜服务器机柜
  16. Cadence Allegro16.6完整安装包+和谐文件 下载
  17. java+ElementUI前后端分离旅游项目第三天 预约管理
  18. 佛系投资---高股息策略
  19. 全球及中国人工沙行业需求前景与发展趋势预测分析报告2022-2028年
  20. c++数据结构二叉树(二叉链表实现)基本操作实现

热门文章

  1. 电脑键盘上的Alt键的作用
  2. [Android各版本特性]Android 4.4 Kitkat
  3. WARNING: --master-data is deprecated and will be removed in a future version
  4. 面试官:设计“抖音”直播功能测试用例吧
  5. 【猿说VUE】Vue过滤器使用介绍(劳动节致敬)
  6. PC网站微信第三方登陆
  7. Flutter 报错:Could not resolve io.flutter:flutter_embedding_debug:1.0.0-ee76268252c22f5c11e82a7b87423c
  8. 从k8s.gcr.io拉取镜像
  9. 中国人的智商全球最高
  10. git 报错解决方法:Your branch is ahead of ‘origin/dev‘ by 65 commits.