HDU-2389
Rain on your Parade
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Others)
Total Submission(s): 2979 Accepted Submission(s): 931
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.
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.
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.
1
2
1 0 3
3 0 3
2
4 0
6 0
1
2
1 1 2
3 3 2
2
2 2
2
2
/**
题意:m个人,n把伞,并且每个人的位置上有个雨下落的速度,然后看能有
多少人能够分到雨伞
做法:二分图最大匹配;
匈牙利算法会超时,时间复杂度是O(VE),
Hopcroft-Carp 算法 时间复杂度是 O(sqrt(n)*E)
**/
#include<stdio.h>
#include<queue>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define eps 1e-6 const int MAXN=;
const int INF=<<;
int g[MAXN][MAXN],Mx[MAXN],My[MAXN],Nx,Ny;
int dx[MAXN],dy[MAXN],dis;
bool vst[MAXN];
struct Node1
{
int x,y,s;
} guests[MAXN];
struct Node2
{
int x,y;
} um[MAXN];
double distance(Node1 a,Node2 b)
{
double x=a.x-b.x;
double y=a.y-b.y; return sqrt(x*x+y*y);
}
bool searchP()
{
queue<int>Q;
dis=INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i=; i<Nx; i++)
if(Mx[i]==-)
{
Q.push(i);
dx[i]=;
}
while(!Q.empty())
{
int u=Q.front();
Q.pop();
if(dx[u]>dis) break;
for(int v=; v<Ny; v++)
if(g[u][v]&&dy[v]==-)
{
dy[v]=dx[u]+;
if(My[v]==-) dis=dy[v];
else
{
dx[My[v]]=dy[v]+;
Q.push(My[v]);
}
}
}
return dis!=INF;
}
bool DFS(int u)
{
for(int v=; v<Ny; v++)
if(!vst[v]&&g[u][v]&&dy[v]==dx[u]+)
{
vst[v]=;
if(My[v]!=-&&dy[v]==dis) continue;
if(My[v]==-||DFS(My[v]))
{
My[v]=u;
Mx[u]=v;
return ;
}
}
return ;
}
int MaxMatch()
{
int res=;
memset(Mx,-,sizeof(Mx));
memset(My,-,sizeof(My));
while(searchP())
{
memset(vst,,sizeof(vst));
for(int i=; i<Nx; i++)
if(Mx[i]==-&&DFS(i)) res++;
}
return res;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n,m,t,i,j;
int T,iCase=;
scanf("%d",&T);
while(T--)
{
iCase++;
scanf("%d",&t);
scanf("%d",&m);
for(i=; i<m; i++)
scanf("%d%d%d",&guests[i].x,&guests[i].y,&guests[i].s);
scanf("%d",&n);
for(i=; i<n; i++)
scanf("%d%d",&um[i].x,&um[i].y);
Nx=m;
Ny=n;
memset(g,,sizeof(g));
for(i=; i<m; i++)
{
for(j=; j<n; j++)
{
if(distance(guests[i],um[j])/guests[i].s-t<eps)
{
g[i][j]=;
}
}
}
printf("Scenario #%d:\n%d\n\n",iCase,MaxMatch());
}
return ;
}
HDU-2389的更多相关文章
- 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 ...
- 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 ...
- hdu 2389(最大匹配bfs版)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成 ...
- (匹配 Hopcroft-Karp算法)Rain on your Parade -- Hdu --2389
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2389 不能用匈牙利,会TEL的,用Hopcroft-Karp Hopcroft-Karp课件 以前是寻找 ...
- 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 ...
- Hdu 2389 二分匹配
题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Ja ...
- HDU 2389 Rain on your Parade
大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再 time 时间内移动到不同的雨伞处(不允许两个人共用一把伞). 输入数据: 第一行是一个T代表T组测试数据 ...
- F - Rain on your Parade - hdu 2389(二分图匹配,Hk算法)
题意:给一些人和一些伞的坐标,然后每个人都有一定的速度,还有多少时间就会下雨,问最多能有多少人可以拿到伞. 分析:题意很明确,可以用每个人和伞判断一下是否能够达到,如果能就建立一个联系.不过这道题的数 ...
- HDU 2389 Rain on your Parade 最大匹配(模板题)【HK算法】
<题目链接> 题目大意:有m个宾客,n把雨伞,预计时间t后将会下大雨,告诉你每个宾客的位置和速度,每把雨伞的位置,问你最多几个宾客能够拿到伞. 解题分析: 本题就是要我们求人与伞之间的最大 ...
- Rain on your Parade HDU - 2389 (hc板题)
在客人能够拿到的伞与客人之间建边 跑hc就好了.... 看看别人的:https://blog.csdn.net/wall_f/article/details/8248350 #include < ...
随机推荐
- [bzoj] 2657 ZJOI2012 旅游 || bfs
原题 题意: 一个多边形,三角剖分,求一条对角线最多能经过多少三角形 题解: 因为不涉及坐标之类的,所以根几何肯定一点关系都没有. 我们会发现,对于有共边的两个三角形,可以被同一条线穿过,而这就相当于 ...
- codevs5037 线段树练习4加强版(暴力分块)
求大爷教线段树怎么写啊QAQ 只会写分块...一开始脑抽写成了O(NKlogN)还被CZL大爷嘲讽了一发T T f[i][j]表示在第i块中,模k为j的数有几个,然后每次修改的时候只需要打个标记,查询 ...
- NOIP2016Day2T3愤怒的小鸟(状压dp) O(2^n*n^2)再优化
看这范围都知道是状压吧... 题目大意就不说了嘿嘿嘿 网上流传的写法复杂度大都是O(2^n*n^2),这个复杂度虽然官方数据可以过,但是在洛谷上会TLE[百度搜出来前几个博客的代码交上去都TLE了], ...
- 搞笑的代码 ( funny )
搞笑的代码 ( funny ) 在OI界存在着一位传奇选手——QQ,他总是以风格迥异的搞笑代码受世人围观 某次某道题目的输入是一个排列,他使用了以下伪代码来生成数据 while 序列长度<n d ...
- Redis 的安装配置介绍
redis 是一个高性能的key-value数据库. redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部 分场合可以对关系数据库起到很好的补充作用.它提供了Pyth ...
- noip模拟赛 保留道路
[问题描述] 很久很久以前有一个国家,这个国家有N个城市,城市由1,2,3,…,N标号,城市间有M条双向道路,每条道路都有两个属性g和s,两个城市间可能有多条道路,并且可能存在将某一城市与其自身连接起 ...
- 工作中常用的Linux命令(不断更新中)
最近工作中用到linux命令,简单总结如下: 1. pwd 查看当前所在的文件路径 2. cd 切换目录 cd .. 切换到上一级目录 3. ls 列出当前文件路径下的所有文件和文件夹 4. ll 是 ...
- book_notes
http://139.196.8.158/ https://caomall.worktile.com/tasks/projects/58fd73047619c44427c0d719 http://lo ...
- 温习js中对象的继承
温故而知新 XD 1. 关于原型和构造函数的几个知识要点: 使用new 操作符调用构造函数,会经历以下四个步骤: 1.1. 创建一个新对象: 1.2. 将构造函数的作用域赋给新对象(因此 this 就 ...
- ZooKeeper开发者指南(五)
引言 这个文档是为了想利用ZooKeeper的协调服务来创建分布式应用的开发者提供的指南.它包括概念和实践的信息. 这个文档的一开始的的四部分呈现了不同ZooKeeper高级概念的的讨论.理解Zook ...