Rain on your Parade

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

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
 
这道题用匈牙利算法会超时,匈牙利算法复杂度O(V*E)
Hopcroft-Carp算法复杂度O(sqrt(V)*E)
/*
ID: LinKArftc
PROG: 2389.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ; struct Node {
double x, y, speed;
Node() {}
Node(double _x, double _y) : x(_x), y(_y) {}
Node(double _x, double _y, double _s) : x(_x), y(_y), speed(_s) {}
} men[maxn], un[maxn]; vector<int>G[maxn];
int uN, vN;
int Mx[maxn],My[maxn];
int dx[maxn],dy[maxn];
int dis;
bool used[maxn];
bool SearchP()
{
queue<int>Q;
dis = INF;
memset(dx,-,sizeof(dx));
memset(dy,-,sizeof(dy));
for(int i = ; i <= uN; i++)
if(Mx[i] == -)
{
Q.push(i);
dx[i] = ;
}
while(!Q.empty())
{
int u = Q.front();
Q.pop();
if(dx[u] > dis)break;
int sz = G[u].size();
for(int i = ;i < sz;i++)
{
int v = G[u][i];
if(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)
{
int sz = G[u].size();
for(int i = ;i < sz;i++)
{
int v = G[u][i];
if(!used[v] && dy[v] == dx[u] + )
{
used[v] = true;
if(My[v] != - && dy[v] == dis)continue;
if(My[v] == - || DFS(My[v]))
{
My[v] = u;
Mx[u] = v;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int res = ;
memset(Mx,-,sizeof(Mx));
memset(My,-,sizeof(My));
while(SearchP())
{
memset(used,false,sizeof(used));
for(int i = ;i <= uN;i++)
if(Mx[i] == - && DFS(i))
res++;
}
return res;
} int main() {
//input;
int T, t, _t = ;
scanf("%d", &T);
while (T --) {
scanf("%d", &t);
scanf("%d", &uN);
for (int i = ; i <= uN; i ++) scanf("%lf %lf %lf", &men[i].x, &men[i].y, &men[i].speed);
scanf("%d", &vN);
for (int i = ; i <= vN; i ++) scanf("%lf %lf", &un[i].x, &un[i].y);
for (int i = ; i <= uN; i ++) {
G[i].clear();
for (int j = ; j <= vN; j ++) {
if (sqrt(fabs(men[i].x - un[j].x) * fabs(men[i].x - un[j].x) + fabs(men[i].y - un[j].y) * fabs(men[i].y - un[j].y)) - men[i].speed * t < eps) G[i].push_back(j);
}
}
printf("Scenario #%d:\n%d\n\n", _t ++, MaxMatch());
} return ;
}

HDU2389(二分图匹配Hopcroft-Carp算法)的更多相关文章

  1. hdu2389二分图之Hopcroft Karp算法

    You're giving a party in the garden of your villa by the sea. The party is a huge success, and every ...

  2. HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)

    题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...

  3. [ACM] HDU 3395 Special Fish (最大重量二分图匹配,KM算法)

    Special Fish Problem Description There is a kind of special fish in the East Lake where is closed to ...

  4. CF1139E Maximize Mex(二分图匹配,匈牙利算法)

    好题.不过之前做过的[SCOI2010]连续攻击游戏跟这题一个套路,我怎么没想到…… 题目链接:CF原网 洛谷 题目大意:在一个学校有 $n$ 个学生和 $m$ 个社团,每个学生有一个非负整数能力值 ...

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

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

  6. 【模板】解决二分图匹配的强力算法——Hopcroft-Karp算法

    详细解释 参见:http://blog.csdn.net/wall_f/article/details/8248373 简要过程 HK算法可以当成是匈牙利算法的优化版,和dinic算法的思想比较类似. ...

  7. hdu2063 二分图匹配,匈牙利算法

    #include <stdio.h> #include <string.h> int n1,n2,m,ans; ]; //记录V2中的点匹配的点的编号 ]; //记录V2中的每 ...

  8. 二分图匹配(KM算法)n^4 分类: ACM TYPE 2014-10-04 11:36 88人阅读 评论(0) 收藏

    #include <iostream> #include<cstring> #include<cstdio> #include<cmath> #incl ...

  9. 二分图匹配(KM算法)n^3 分类: ACM TYPE 2014-10-01 21:46 98人阅读 评论(0) 收藏

    #include <iostream> #include<cstring> #include<cstdio> #include<cmath> const ...

  10. Codevs 1222 信与信封问题 二分图匹配,匈牙利算法

    题目: http://codevs.cn/problem/1222/ 1222 信与信封问题   时间限制: 1 s   空间限制: 128000 KB   题目等级 : 钻石 Diamond 题解 ...

随机推荐

  1. django中判断当前user具有是否有对模块的增删改查权限

    首先简单了解一下user的一些属性 User对象 User对象是认证系统的核心.用户对象通常用来代表网站的用户,并支持例如访问控制.注册用户.关联创建者和内容等.在Django认证框架中只有一个用户类 ...

  2. extjs/js时间校验

    //时间秒判断var re=/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:( ...

  3. ORM选型对比

    ORM框架选型 ORM框架选型 jian A YEAR AGO (2017-04-10) orm, database 选型标准:实现O/R mapping,基于promise,支持原生SQL语句,支持 ...

  4. ubuntu中执行truffle build出现问题

    进行build之前,采用默认构建器方式创建客户端,先安装默认构建器: npm install truffle-default-builder --save 然后需要修改truffle.js配置文件如下 ...

  5. @section script{}的使用

    1,MVC视图中,JS代码被放在下面的Razor代码中(@section script{}) 2,这样做的好处是:在视图进行JS编码时是一个很好 的实践,在共享视图(_layout.cshtml),存 ...

  6. Delphi 7学习开发控件(续)

    继上次我们学习开发一个简单的画线控件后,基本的制作控件步骤已经清楚了,这次我们继续加深学习控件的制作.我们打开Delphi 7创建一个应用程序,拖动LineTo控件到窗体上,仔细看左边的对象设计器,可 ...

  7. WebSocket简单介绍(WebSocket 实战)(3)

    这一节里我们用一个案例来演示怎么使用 WebSocket 构建一个实时的 Web 应用.这是一个简单的实时多人聊天系统,包括客户端和服务端的实现.客户端通过浏览器向聊天服务器发起请求,服务器端解析客户 ...

  8. android 与 小米1S刷机学习

    本文内容为本博客作者原创,转载请注明出处或者发私信. [名词] 1.ROM包 :安卓手机系统,以.ZIP结尾,类似windows的 win7系统包,300M-700M不止 2.卡刷(Recovery模 ...

  9. 【题解】HAOI2007分割矩阵

    水题盛宴啦啦啦……做起来真的极其舒服,比某些毒瘤题好太多了…… 数据范围极小 --> 状压 / 搜索 / 高维度dp:观察要求的均方差,开始考虑是不是能够换一下式子.我们用\(a_{x}\)来表 ...

  10. BZOJ4568 [Scoi2016]幸运数字 【点分治 + 线性基】

    题目链接 BZOJ4568 题解 选任意个数异或和最大,使用线性基 线性基插入\(O(logn)\),合并\(O(log^2n)\) 我们要求树上两点间异或和最大值,由于合并是\(O(log^2n)\ ...