Rain on your Parade

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

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

 
题意:n个人匹配m把伞,问最多能有多少匹配?
题解:HK算法减少时间.
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int INF = ;
struct Node
{
int x,y,v;
} p[N],ub[N];
int graph[N][N];
int n,m,dist;
bool vis[N];
int cx[N],cy[N],dx[N],dy[N];
int dis(Node a,Node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool searchpath()
{
queue<int> Q;
dist=INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i=;i<=n;i++)
{
if(cx[i]==-)
{
Q.push(i);
dx[i]=;
}
}
while(!Q.empty())
{
int u=Q.front();
Q.pop();
if(dx[u]>dist) break;
for(int v=;v<=n;v++)
{
if(graph[u][v]&&dy[v]==-)
{
dy[v]=dx[u]+;
if(cy[v]==-) dist=dy[v];
else
{
dx[cy[v]]=dy[v]+;
Q.push(cy[v]);
}
}
}
}
return dist!=INF;
}
int findpath(int u)
{
for(int v=;v<=m;v++)
{
if(!vis[v]&&graph[u][v]&&dy[v]==dx[u]+)
{
vis[v]=;
if(cy[v]!=-&&dy[v]==dist)
{
continue;
}
if(cy[v]==-||findpath(cy[v]))
{
cy[v]=u;cx[u]=v;
return ;
}
}
}
return ;
}
void MaxMatch()
{
int res=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
while(searchpath())
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
if(cx[i]==-)
{
res+=findpath(i);
}
}
}
printf("%d\n\n",res);;
}
int main()
{
int tcase;
scanf("%d",&tcase);
int t = ;
while(tcase--)
{
memset(graph,,sizeof(graph));
int time;
scanf("%d",&time);
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int v;
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].v);
}
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&ub[i].x,&ub[i].y);
}
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(dis(p[i],ub[j])<=p[i].v*p[i].v*time*time)
{
graph[i][j] = ;
}
}
}
printf("Scenario #%d:\n",t++);
MaxMatch();
}
return ;
}

hdu 2389(二分图hk算法模板)的更多相关文章

  1. HDU 1083 - Courses - [匈牙利算法模板题]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...

  2. HDU 2586 ( LCA/tarjan算法模板)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:n个村庄构成一棵无根树,q次询问,求任意两个村庄之间的最短距离 思路:求出两个村庄的LCA,d ...

  3. HDU 2255 二分图最佳匹配 模板题

    题目大意: 给定每一个人能支付的房子价值,每个人最多且必须拥有一套房子,问最后分配房子可得到的最大收益 抄了个别人的KM模板,就这样了... #include <cstdio> #incl ...

  4. POJ1325机器重启次数——二分图匈牙利算法模板

    题目:http://poj.org/problem?id=1325 求最小点覆盖.输出最大匹配数就行,结果略复杂地弄了. 注意由题可知 可以直接把与0有关的边删掉.不过亲测不删0而计数时不计0就会WA ...

  5. HK算法模板+小优化(跑的快一点点)

    HUST 2604 #include <iostream> #include <cstdlib> #include <cstdio> #include <cs ...

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

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

  7. HDU 5727 - Necklace - [全排列+二分图匹配][Hopcroft-Karp算法模板]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. ...

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

  9. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

随机推荐

  1. 51nod 1274 最长递增路径(DP)

    一开始自己想了一种跑的巨慢..写了题解的做法又跑的巨快..一脸懵逼 显然要求边权递增就不可能经过重复的边了,那么设f[i]为第i条边出发能走多远就好了,这是我一开始的写法,可能dfs冗余状态较多,跑的 ...

  2. purfer序列题表

    purfer序列是对于带编号(互不相同)的无根树进行编码得到的,对于同样的n个顶点,其有n-2项,有n^(n-2)种,而且每种都合法(如果只要求他是一棵树的话)(可以通过证明翻译过程维持了各部分的树的 ...

  3. C/C++中字符串与数字相互转换

    数字转字符串: 用C++的streanstream: #include <sstream> #Include <string> string num2str(double i) ...

  4. 解决requests获取源代码时中文乱码问题

    用requests获取源代码时,如果是中文网页,就可能会出现乱码,下面我以中关村的网站为例: import requests url = 'http://desk.zol.com.cn/meinv/' ...

  5. TCP的连接(三次握手)和释放(四次挥手)

    1 http都设置哪些header? http协议规定:一个完整的客户端发送给服务端的HTTP请求包括: (1)请求行:包括了请求方法.请求资源路径.HTTP协议版本,eg:GET/Server/im ...

  6. ReentrantLock和synchronized区别和联系?

    相同:ReentrantLock提供了synchronized类似的功能和内存语义,都是可重入锁. 不同: 1.ReentrantLock功能性方面更全面,比如时间锁等候,可中断锁等候,锁投票等,因此 ...

  7. iostat和iowait详细解说

    简单的说,sar -u看出来的cpu利用率iowait 不实用,iostat -x 中的 svctm   和util 参数 命令形式: iostat -x 1 每隔一秒输出下 其中的svctm参数代表 ...

  8. java正则 以什么开始,以什么结束

    public class RegTest { public static void main(String[] args){ String regex = "\\[([\\s\\S]*?)\ ...

  9. 整数中1出现的次数(从1到n整数中1出现的次数)

    整数中1出现的次数(从1到n整数中1出现的次数) 题目描述 求出1 ~ 13的整数中1出现的次数,并算出100 ~ 1300的整数中1出现的次数?为此他特别数了一下1 ~ 13中包含1的数字有1.10 ...

  10. NDK---使用,开发步骤

    使用NDk的场景: 1.某些方法,是使用C,C++本地代码实现的,然后,我想在Java中调用这些方法.这个时候,就需要使用到JNI技术. 应用NDK的时候,分两个部分,Java部分,JNI层部分,本地 ...