Rain on your Parade

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

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
 

Hopcroft-Carp算法

测试下模板,还是很快的

  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <vector>
  6. #include <queue>
  7. using namespace std;
  8. /* *******************************
  9. * 二分图匹配(Hopcroft-Carp算法)
  10. * 复杂度O(sqrt(n)*E)
  11. * 邻接表存图,vector实现
  12. * vector先初始化,然后假如边
  13. * uN 为左端的顶点数,使用前赋值(点编号0开始)
  14. */
  15. const int MAXN = ;
  16. const int INF = 0x3f3f3f3f;
  17. vector<int>G[MAXN];
  18. int uN;
  19.  
  20. int Mx[MAXN],My[MAXN];
  21. int dx[MAXN],dy[MAXN];
  22. int dis;
  23. bool used[MAXN];
  24. bool SearchP()
  25. {
  26. queue<int>Q;
  27. dis = INF;
  28. memset(dx,-,sizeof(dx));
  29. memset(dy,-,sizeof(dy));
  30. for(int i = ; i < uN; i++)
  31. if(Mx[i] == -)
  32. {
  33. Q.push(i);
  34. dx[i] = ;
  35. }
  36. while(!Q.empty())
  37. {
  38. int u = Q.front();
  39. Q.pop();
  40. if(dx[u] > dis)break;
  41. int sz = G[u].size();
  42. for(int i = ;i < sz;i++)
  43. {
  44. int v = G[u][i];
  45. if(dy[v] == -)
  46. {
  47. dy[v] = dx[u] + ;
  48. if(My[v] == -)dis = dy[v];
  49. else
  50. {
  51. dx[My[v]] = dy[v] + ;
  52. Q.push(My[v]);
  53. }
  54. }
  55. }
  56. }
  57. return dis != INF;
  58. }
  59. bool DFS(int u)
  60. {
  61. int sz = G[u].size();
  62. for(int i = ;i < sz;i++)
  63. {
  64. int v = G[u][i];
  65. if(!used[v] && dy[v] == dx[u] + )
  66. {
  67. used[v] = true;
  68. if(My[v] != - && dy[v] == dis)continue;
  69. if(My[v] == - || DFS(My[v]))
  70. {
  71. My[v] = u;
  72. Mx[u] = v;
  73. return true;
  74. }
  75. }
  76. }
  77. return false;
  78. }
  79. int MaxMatch()
  80. {
  81. int res = ;
  82. memset(Mx,-,sizeof(Mx));
  83. memset(My,-,sizeof(My));
  84. while(SearchP())
  85. {
  86. memset(used,false,sizeof(used));
  87. for(int i = ;i < uN;i++)
  88. if(Mx[i] == - && DFS(i))
  89. res++;
  90. }
  91. return res;
  92. }
  93.  
  94. struct Point
  95. {
  96. int x,y,s;
  97. void input1()
  98. {
  99. scanf("%d%d%d",&x,&y,&s);
  100. }
  101. void input2()
  102. {
  103. scanf("%d%d",&x,&y);
  104. }
  105. };
  106. int dis2(Point a,Point b)
  107. {
  108. return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
  109. }
  110. Point p1[MAXN],p2[MAXN];
  111.  
  112. int main()
  113. {
  114. int T;
  115. int t;
  116. int iCase = ;
  117. int n,m;
  118. scanf("%d",&T);
  119. while(T--)
  120. {
  121. iCase++;
  122. scanf("%d",&t);
  123. scanf("%d",&n);
  124. for(int i = ;i < n;i++)
  125. p1[i].input1();
  126. scanf("%d",&m);
  127. for(int i = ;i < m;i++)
  128. p2[i].input2();
  129. for(int i = ;i < n;i++)
  130. G[i].clear();
  131. uN = n;
  132. for(int i = ;i < n;i++)
  133. for(int j = ;j < m;j++)
  134. if(dis2(p1[i],p2[j]) <= p1[i].s*p1[i].s*t*t)
  135. G[i].push_back(j);
  136. printf("Scenario #%d:\n",iCase);
  137. printf("%d\n\n",MaxMatch());
  138. }
  139. return ;
  140. }

HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)的更多相关文章

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

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

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

  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(二分匹配HK算法)

    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 2389 Rain on your Parade 最大匹配(模板题)【HK算法】

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

  7. HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDOJ 2389 Rain on your Parade

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

  9. HDU 6178 Monkeys(树上的二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过 ...

随机推荐

  1. C#通过反射获取类中的方法和参数个数,反射调用方法带参数

    using System; using System.Reflection; namespace ConsoleApp2 { class Program { static void Main(stri ...

  2. linux命令(2):grep命令

    实例一: a.log文件内容如下: 从 a.log 文件中提取包含“WARNING”或”FATAL”,同时不包含“IGNOR”的行 grep -E 'WARNING|FATAL' a.log | gr ...

  3. NativeScriptEngineService 被调用流程

    AbsractSearchScritp 有个lookup! NativeScriptEngineService search()会调用 script.setLookup() NativeScriptE ...

  4. servlet学习记录:Servlet中的service()方法

    Servlet的生存时间是由init,service,destory方法构成,这里分析一下service这个方法 Servlet接口中定义了一个service()方法,而我们一般是使用HttpServ ...

  5. maven项目的pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0 " 2 xmlns:xsi="http://www.w3.org ...

  6. AC日记——[HNOI2014]世界树 bzoj 3572

    3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...

  7. 求问asp.net mvc发布问题

    正常发布 浏览后如下

  8. 本人博客已经搬至SegmentFault.com

    本人博客已经搬至SegmentFault.com 具体链接:http://segmentfault.com/blog/zhoutk

  9. LoadRunner:关联HTTP请求

    LoadRunner:关联HTTP请求 本例通过一个使用HTTP/HTML协议发送.获取服务器数据的vuser脚本,分析LoadRunner如何进行HTTP关联. 下面这个例子包括两个事务:上传数据到 ...

  10. 使用keras时出现 `pydot` failed to call GraphViz的解决办法

    问题来源于使用了 keras.utils.plot_model,报错内容为: 2018-08-29 08:58:21.937037: I tensorflow/core/platform/cpu_fe ...