题目链接:https://vjudge.net/problem/HDU-2389

Rain on your Parade

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 4889    Accepted Submission(s): 1612

Problem Description
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 <= 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.
 
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:
2

Scenario #2:
2

 
Source
 
Recommend
lcy

题解:

就直接求二分图最大匹配,不过由于数据较大,匈牙利算法超时,所以需要用HK算法。

代码如下:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <set>
  9. #include <queue>
  10. #include <sstream>
  11. #include <algorithm>
  12. using namespace std;
  13. const int INF = 2e9;
  14. const int MOD = 1e9+;
  15. const int MAXN = +;
  16.  
  17. struct Node
  18. {
  19. int x, y, speed;
  20. }gue[MAXN], umb[MAXN];
  21.  
  22. int uN, vN, t;
  23. vector<int>g[MAXN];
  24.  
  25. int Mx[MAXN], My[MAXN];
  26. int dx[MAXN], dy[MAXN];
  27. int dis;
  28. bool used[MAXN];
  29.  
  30. bool SearchP()
  31. {
  32. queue<int>Q;
  33. dis = INF;
  34. memset(dx, -, sizeof(dx));
  35. memset(dy, -, sizeof(dy));
  36. for(int i = ; i<=uN; i++)
  37. if(Mx[i]==-)
  38. {
  39. Q.push(i);
  40. dx[i] = ;
  41. }
  42.  
  43. while(!Q.empty())
  44. {
  45. int u = Q.front();
  46. Q.pop();
  47. if(dx[u]>dis) break;
  48. int sz = g[u].size();
  49. for(int i = ; i<sz; i++)
  50. {
  51. int v = g[u][i];
  52. if(dy[v]==-)
  53. {
  54. dy[v] = dx[u] + ;
  55. if(My[v]==-) dis = dy[v];
  56. else
  57. {
  58. dx[My[v]] = dy[v] + ;
  59. Q.push(My[v]);
  60. }
  61. }
  62. }
  63. }
  64. return dis!=INF;
  65. }
  66.  
  67. bool DFS(int u)
  68. {
  69. int sz = g[u].size();
  70. for(int i = ; i<sz; i++)
  71. {
  72. int v = g[u][i];
  73. if(!used[v] && dy[v]==dx[u]+)
  74. {
  75. used[v] = true;
  76. if(My[v]!=- && dy[v]==dis) continue;
  77. if(My[v]==- || DFS(My[v]))
  78. {
  79. My[v] = u;
  80. Mx[u] = v;
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87.  
  88. int MaxMatch()
  89. {
  90. int res = ;
  91. memset(Mx, -, sizeof(Mx));
  92. memset(My, -, sizeof(My));
  93. while(SearchP())
  94. {
  95. memset(used, false, sizeof(used));
  96. for(int i = ; i<=uN; i++)
  97. if(Mx[i]==- && DFS(i))
  98. res++;
  99. }
  100. return res;
  101. }
  102.  
  103. int main()
  104. {
  105. int T, kase = ;
  106. scanf("%d", &T);
  107. while(T--)
  108. {
  109. scanf("%d%d", &t, &uN);
  110. for(int i = ; i<=uN; i++)
  111. {
  112. scanf("%d%d%d", &gue[i].x, &gue[i].y, &gue[i].speed);
  113. g[i].clear();
  114. }
  115.  
  116. scanf("%d", &vN);
  117. for(int i = ; i<=vN; i++)
  118. scanf("%d%d", &umb[i].x, &umb[i].y);
  119.  
  120. for(int i = ; i<=uN; i++)
  121. for(int j = ; j<=vN; j++)
  122. {
  123. int dis = (gue[i].x-umb[j].x)*(gue[i].x-umb[j].x)
  124. +(gue[i].y-umb[j].y)*(gue[i].y-umb[j].y);
  125. int s = gue[i].speed*gue[i].speed*t*t;
  126. if(s>=dis) g[i].push_back(j);
  127. }
  128.  
  129. int ans = MaxMatch();
  130. printf("Scenario #%d:\n%d\n\n", ++kase, ans);
  131.  
  132. }
  133. }

HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法的更多相关文章

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

  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算法)

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

  4. SPOJ 4206 Fast Maximum Matching (二分图最大匹配 Hopcroft-Carp 算法 模板)

    题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围:  1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应 ...

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

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

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

  7. UESTC 919 SOUND OF DESTINY --二分图最大匹配+匈牙利算法

    二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). ...

  8. HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  9. 51Nod 2006 飞行员配对(二分图最大匹配)-匈牙利算法

    2006 飞行员配对(二分图最大匹配) 题目来源: 网络流24题 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 第二次世界大战时期,英国皇家空军从沦陷国 ...

随机推荐

  1. 基于 WPF + Modern UI 的 公司OA小助手 开发总结

    前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个阶段的一个反思.人只有在总结的过程中才会发现自己的不足. 公司每天都要在OA系统上上班点击签到,下班点击签退 ...

  2. Boolean.valueOf("true")的用法

    Boolean.valueOf(a);a为true时返回true不管大小写,a为其他值时都返回false:

  3. 【ITOO 2】.NET 动态建库建表:使用SQL字符串拼接方式

    导读:在最近接手的项目(高效云平台)中,有一个需求是要当企业用户注册时,给其动态的新建一个库和表.刚开始接手的时候,是一点头绪都没有,然后查了一些资料,也问了问上一版本的师哥师姐,终于有了点头绪.目前 ...

  4. [luoguP2679] 子串(DP)

    传送门 气死我了,自己YY的方法只能得70分. 一个下午都在搞这道题. 至于正解,真的不想写了. 请移步 here #include <cstdio> #define M 201 #def ...

  5. BZOJ1775: [Usaco2009 Dec]Vidgame 电视游戏问题

    n<=50个游戏机有花费,每个游戏机有Gi<=10种游戏,每种游戏有花费有收益,买了游戏机才能玩对应游戏,求最大收益. 这就是一个背包!不过有依存关系,就不会了! 方法一:f[i][j]表 ...

  6. IText 生成pdf,处理table cell列跨页缺失的问题

    /**     * 创建(table)PDF,处理cell 跨页处理     * @param savePath(需要保存的pdf路径)     * @param pmbs (数据库查询的数据)    ...

  7. Spring Boot中实现logback多环境日志配置

    在Spring Boot中,可以在logback.xml中的springProfile标签中定义多个环境logback.xml: <springProfile name="produc ...

  8. sql server2008 R2 各个版本的区别与选择

    目前已知的SQL Server 2008 R2的版本有: 企业版.标准版.工作组版.Web版.开发者版.Express版.Compact 3.5版. 这个次序也是各个版本功能的强大程度从高到低的一个排 ...

  9. 【APUE】进程间通信之信号量

    信号量是一个计数器,用于多进程对共享数据对象的访问 为了获得共享资源,进程需要执行下列操作: 1)测试控制该资源的信号量 2)若此信号量为正,则进程可以使用该资源,进程将信号量减1,表示它使用了一个资 ...

  10. [Rust] Load a WebAssembly Function Written in Rust and Invoke it from JavaScript

    In this lesson we are going to setup a project from scratch by introducing the JavaScript snippet to ...