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/Others)
Total Submission(s): 2154 Accepted Submission(s): 662
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.
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
2
Scenario #2:
2
Hopcroft-Carp算法
测试下模板,还是很快的
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;
/* *******************************
* 二分图匹配(Hopcroft-Carp算法)
* 复杂度O(sqrt(n)*E)
* 邻接表存图,vector实现
* vector先初始化,然后假如边
* uN 为左端的顶点数,使用前赋值(点编号0开始)
*/
const int MAXN = ;
const int INF = 0x3f3f3f3f;
vector<int>G[MAXN];
int uN; 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;
} struct Point
{
int x,y,s;
void input1()
{
scanf("%d%d%d",&x,&y,&s);
}
void input2()
{
scanf("%d%d",&x,&y);
}
};
int dis2(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
Point p1[MAXN],p2[MAXN]; int main()
{
int T;
int t;
int iCase = ;
int n,m;
scanf("%d",&T);
while(T--)
{
iCase++;
scanf("%d",&t);
scanf("%d",&n);
for(int i = ;i < n;i++)
p1[i].input1();
scanf("%d",&m);
for(int i = ;i < m;i++)
p2[i].input2();
for(int i = ;i < n;i++)
G[i].clear();
uN = n;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
if(dis2(p1[i],p2[j]) <= p1[i].s*p1[i].s*t*t)
G[i].push_back(j);
printf("Scenario #%d:\n",iCase);
printf("%d\n\n",MaxMatch());
}
return ;
}
HDU 2389 Rain on your Parade(二分匹配,Hopcroft-Carp算法)的更多相关文章
- 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 3289 Rain on your Parade (二分图匹配 Hopcroft-Karp)
题目链接: Hdu 3289 Rain on your Parade 题目描述: 有n个客人,m把雨伞,在t秒之后将会下雨,给出每个客人的坐标和每秒行走的距离,以及雨伞的位置,问t秒后最多有几个客人可 ...
- 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.rain on your parade(二分匹配HK算法)
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
- HDU 2389 Rain on your Parade
大意:在一个二维坐标系上有nx个人和ny把伞,每个人都有自己的移动速度,问有多少人可以再 time 时间内移动到不同的雨伞处(不允许两个人共用一把伞). 输入数据: 第一行是一个T代表T组测试数据 ...
- HDU 2389 Rain on your Parade 最大匹配(模板题)【HK算法】
<题目链接> 题目大意:有m个宾客,n把雨伞,预计时间t后将会下大雨,告诉你每个宾客的位置和速度,每把雨伞的位置,问你最多几个宾客能够拿到伞. 解题分析: 本题就是要我们求人与伞之间的最大 ...
- HDU 1150:Machine Schedule(二分匹配,匈牙利算法)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2389 Rain on your Parade
HK.... Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K ...
- HDU 6178 Monkeys(树上的二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过 ...
随机推荐
- 安全测试===sqlmap(肆)转载
十八.杂项 1.使用简写 参数:-z 有些参数组合是被经常用到的,如“--batch --random-agent --ignore-proxy --technique=BEU”,这样写一大串很不好看 ...
- (十六)strtok、strtok_s、strtok_r 字符串分割函数
1.strtok函数 函数原型:char * strtok (char *str, const char * delimiters); 参数:str,待分割的字符串(c-string):delimit ...
- 解决springmvc+fastjson返回页面出现乱码问题
在controller里面的接口上面加,produces="text/html;charset=UTF-8"即可 @RequestMapping(value = "/ad ...
- hdu 1455(DFS+好题+经典)
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- AC日记——【模板】点分治(聪聪可可) 洛谷 P2634
[模板]点分治(聪聪可可) 思路: 点分治: (感谢灯神) 代码: #include <bits/stdc++.h> using namespace std; #define maxn 2 ...
- CentOS7安装私有gitlab
1.安装依赖包 yum install -y curl policycoreutils openssh-server openssh-clients postfix systemctl start p ...
- centos7 mariaDB安装
参考:http://www.linuxidc.com/Linux/2016-03/128880.htm
- Java之IO流的关闭
1.在finally中关闭流: OutputStream out = null; try { out = new FileOutputStream(""); // ...操作流代码 ...
- HDU 6166 Senior Pan (最短路变形)
题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...
- 洛谷P2587 [ZJOI2008] 泡泡堂
题目传送门 分析:一道策略游戏题,要求最大期望得分和最小期望得分.首先分析最大,很显然是可以用一种类似于田忌赛马的思维来做,将两队的实力按照从大到小(其实从小到大也可以)排序,然后就按照顺序比较,可能 ...