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

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 
 
Sample Output
Scenario #1:
2

Scenario #2:
2
 
Source
 
Recommend
lcy
/**
题意: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的更多相关文章

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

  3. hdu 2389(最大匹配bfs版)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成 ...

  4. (匹配 Hopcroft-Karp算法)Rain on your Parade -- Hdu --2389

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2389 不能用匈牙利,会TEL的,用Hopcroft-Karp Hopcroft-Karp课件 以前是寻找 ...

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

  6. Hdu 2389 二分匹配

    题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Ja ...

  7. HDU 2389 Rain on your Parade

    大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再 time 时间内移动到不同的雨伞处(不允许两个人共用一把伞).   输入数据: 第一行是一个T代表T组测试数据 ...

  8. F - Rain on your Parade - hdu 2389(二分图匹配,Hk算法)

    题意:给一些人和一些伞的坐标,然后每个人都有一定的速度,还有多少时间就会下雨,问最多能有多少人可以拿到伞. 分析:题意很明确,可以用每个人和伞判断一下是否能够达到,如果能就建立一个联系.不过这道题的数 ...

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

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

  10. Rain on your Parade HDU - 2389 (hc板题)

    在客人能够拿到的伞与客人之间建边  跑hc就好了.... 看看别人的:https://blog.csdn.net/wall_f/article/details/8248350 #include < ...

随机推荐

  1. [Leetcode] search in rotated sorted array 搜索旋转有序数组

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e.,0 1 2 4 5 6 7might ...

  2. BZOJ3495 PA2010 Riddle 【2-sat】

    题目链接 BZOJ3495 题解 每个城市都有选和不选两种情况,很容易考虑到2-sat 边的限制就很好设置了,主要是每个郡只有一个首都的限制 我们不可能两两之间连边,这样复杂度就爆炸了 于是乎就有了一 ...

  3. [POI2014]DOO-Around the world

    通过几年的努力,Byteasar最终拿到了飞行员驾驶证.为了庆祝这一事实,他打算买一架飞机并且绕Byteotia星球赤道飞行一圈.但不幸的是赤道非常长所以需要中途加几次油.现在已知赤道上面所有飞机场, ...

  4. JavaScript引擎是单线程的

    从基础的层面来讲,理解JavaScript的定时器是如何工作的是非常重要的.计时器的执行常常和我们的直观想象不同,那是因为JavaScript引擎是单线程的.我们先来认识一下下面三个函数是如何控制计时 ...

  5. 创建JavaScript的哈希表Hashtable

    Hashtable是最常用的数据结构之一,但在JavaScript里没有各种数据结构对象.但是我们可以利用动态语言的一些特性来实现一些常用的数据结构和操作,这样可以使一些复杂的代码逻辑更清晰,也更符合 ...

  6. angularJS 条件查询 品优购条件查询品牌(条件查询和列表展示公用方法解决思路 及 post请求混合参数提交方式)

    Brand.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  7. Linux试题

    1.编写脚本,统计/etc./usr./var目录中有多少个一级子目录和文件 #!/bin/bash # danran # time is Mon Jun 5 13:09:12 CST 2017 li ...

  8. JQuery学习四(过滤选择器)

    :first选择第一个元素.$(“div:first”)进行选择第一个<div> :last 选择最后一个最后一个元素 $("div:last")选取最后一个<d ...

  9. NOJ/HUST 1095 校赛 Just Go 线段树模板题

    Description There is a river, which contains n stones from left to right. These stones are magic, ea ...

  10. 深入理解微服务架构spring的各个知识点(面试必问知识点)

    什么是spring spring是一个开源框架,spring为简化企业级开发而生,使用spring可以使简单的java bean 实现以前只有EJG才能实现的功能. Spring是一个轻量级的控制反转 ...