Rain on your Parade

时间:2022-09-06 19:12:22

Rain on your Parade

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

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
HDU 2008-10 Public Contest

Recommend
lcy

一看就是求二分图的最大匹配,不过点太多了匈牙利不行,要用Hopcroft_Karp.别人的代码没看懂,不过幸好接口用起来挺方便.贴上大牛的代码:

#include<cstring>   //HK算法。。
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector> using namespace std;
const int maxn=;
int n,m;
struct Pos{
int x,y;
}man[maxn],umbr[maxn];
vector<int> child[maxn];
int speed[maxn];//人的速度
int cx[maxn],cy[maxn];//集合X Y的匹配值
int distx[maxn],disty[maxn];//记录距离 bool bfs(){
bool flag=false;
memset(distx,,sizeof(distx));//距离初始为0
memset(disty,,sizeof(disty)); queue<int> que;
for(int i=;i<=n;i++)//把X集合中 所有未匹配的加入队列
if(cx[i]==-)
que.push(i);
while(!que.empty())//集合非空
{
int x=que.front();
que.pop();
for(int i = ; i < child[ x ].size() ; i++ )//所有以i为起点的边
{
int y = child[ x ][ i ];
if( !disty[ y ] )//该边未被使用
{
disty[ y ]=distx[ x ] + ;//距离+1
if(cy[ y ] == -) flag=true;//该点未被使用可以增加匹配
else
{
distx[ cy[ y ] ]= disty[ y ] + ;
que.push( cy[ y ] );
}
}
}
}
return flag;
}
bool dfs(int x){//寻找增广路
for(int i=;i<child[x].size();i++)//枚举所有以i为起点的边
{
int y=child[x][i];
if(disty[ y ] == distx[ x ]+)//距离刚好为1表明相连
{
disty[ y ] = ;
if(cy[ y ] == - || dfs( cy[ y ] ))//找到一条增广路
{
cx[ x ] = y ; cy[ y ] = x;//保存匹配值
return true;
}
}
}
return false;
}
int Hopcroft_Karp(){
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
int ans=;
while(bfs())//如果距离更新成功,X集合中每一个点找一次增广路
{
for(int i=;i<=n;i++)
if(cx[i]==- && dfs(i))
ans++;
}
return ans;
} double dis(int i,int j){
return sqrt( (double)(man[i].x-umbr[j].x)*(man[i].x-umbr[j].x)+ (man[i].y-umbr[j].y)*(man[i].y-umbr[j].y) );
}
int main(){
int t,cas=,time;
scanf("%d",&t);
while(t--){
scanf("%d%d",&time,&n);
for(int i=;i<=n;i++)
scanf("%d%d%d",&man[i].x,&man[i].y,&speed[i]); scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d%d",&umbr[i].x,&umbr[i].y); for(int i=;i<=n;i++)
child[i].clear(); for(int i=;i<=n;i++)//能够在下雨前拿到伞的建一条边
for(int j=;j<=m;j++)
if(speed[i]*time >= dis(i,j))
child[i].push_back(j); printf("Scenario #%d:\n",++cas);
printf("%d\n",Hopcroft_Karp());
printf("\n"); }
}

Rain on your Parade的更多相关文章

  1. HDOJ 2389 Rain on your Parade

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

  2. HDU 2389 Rain on your Parade &sol; 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 ...

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

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

  5. HDU2389:Rain on your Parade(二分图最大匹配&plus;HK算法)

    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——————【Hopcroft-Karp求最大匹配、sqrt&lpar;n&rpar;&ast;e复杂度】

    Rain on your Parade Time Limit:3000MS     Memory Limit:165535KB     64bit IO Format:%I64d & %I64 ...

  7. HDU2389 Rain on your Parade —— 二分图最大匹配 HK算法

    题目链接:https://vjudge.net/problem/HDU-2389 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)  ...

  8. Hdu 3289 Rain on your Parade &lpar;二分图匹配 Hopcroft-Karp&rpar;

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

  9. hdu-2389&period;rain on your parade&lpar;二分匹配HK算法&rpar;

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

随机推荐

  1. asp&period;net MVC ajax上传文件

    普通上传 view: <body> <form id="form1" method="post" action="@Url.Acti ...

  2. 为什么要用Hibernate框架&quest; 把SessionFactory&comma;Session&comma;Transcational封装成包含crud的工具类并且处理了事务&comma;那不是用不着spring了&quest;

    既然用Hibernate框架访问管理持久层,那为何又提到用Spring来管理以及整合Hibernate呢?把SessionFactory,Session,Transcational封装成包含crud的 ...

  3. tomcat&plus;spring&plus;https

    由于开发的接口需要ios调用,而ios即将只支持https,所以最近研究了一下,将成果放在这里记录一下: .配置tomcat的https: 原文链接:http://jingyan.baidu.com/ ...

  4. ASP&period;NET数据绑定控件简介

    •数据绑定分为数据源和数据绑定控件两部分(①数据绑定控件通过数据源获取和修改数据②数据绑定控件通过数据源隔离数据提供者和数据使用者)数据绑定控件→数据源→数据库•数据源:SqlDataSource(连 ...

  5. android的Log日志打印管理工具类&lpar;一&rpar;

    android的Log日志的打印管理工具类: package com.gzcivil.utils; import android.util.Log; /** * 日志打印管理 * * @author ...

  6. endnote X7 加入文献

    endnote可以管理文献,并且在word中方便的添加参考文献. 1.加入文献: 2.导入以后可以创建自己的group,然后把导入的参考文献拖到group里,这样方便在插入参考文献的时候用group名 ...

  7. web正则表达式与示例

    正则表达式应用——实例应用: 1.验证用户名和密码:("^[a-zA-Z]\w{5,15}$")正确格式:"[A-Z][a-z]_[0-9]"组成,并且第一个字 ...

  8. ●CodeForces 698C LRU

    题链: http://codeforces.com/problemset/problem/698/C题解.1: 概率dp,状压dp 棒棒哒题解:https://www.cnblogs.com/liu- ...

  9. ie9上传文件

    兼容ie9文件上传,解决ie9下提示下载或保存 如果不考虑ie9兼容性,实现[上传图片]大致的思路如下: 由于公司是将所有上传的图片都放到[代理服务器]里.所以[上传图片]其实是上传到[代理服务器]. ...

  10. 第4次oo作业

    作业概述 作业1:多项式加法 第一次作业理解上并不困难,简言之是一个多项式合并同类项,但对于我这个第一次使用java进行编程的小白,还是充满了血和泪. 在这次课程之前,我稍微对java有一些了解,但也 ...