HDU2389(二分图匹配Hopcroft-Carp算法)
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
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.
2
2
/*
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算法)的更多相关文章
- 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 ...
- HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...
- [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 ...
- CF1139E Maximize Mex(二分图匹配,匈牙利算法)
好题.不过之前做过的[SCOI2010]连续攻击游戏跟这题一个套路,我怎么没想到…… 题目链接:CF原网 洛谷 题目大意:在一个学校有 $n$ 个学生和 $m$ 个社团,每个学生有一个非负整数能力值 ...
- F - Rain on your Parade - hdu 2389(二分图匹配,Hk算法)
题意:给一些人和一些伞的坐标,然后每个人都有一定的速度,还有多少时间就会下雨,问最多能有多少人可以拿到伞. 分析:题意很明确,可以用每个人和伞判断一下是否能够达到,如果能就建立一个联系.不过这道题的数 ...
- 【模板】解决二分图匹配的强力算法——Hopcroft-Karp算法
详细解释 参见:http://blog.csdn.net/wall_f/article/details/8248373 简要过程 HK算法可以当成是匈牙利算法的优化版,和dinic算法的思想比较类似. ...
- hdu2063 二分图匹配,匈牙利算法
#include <stdio.h> #include <string.h> int n1,n2,m,ans; ]; //记录V2中的点匹配的点的编号 ]; //记录V2中的每 ...
- 二分图匹配(KM算法)n^4 分类: ACM TYPE 2014-10-04 11:36 88人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> #incl ...
- 二分图匹配(KM算法)n^3 分类: ACM TYPE 2014-10-01 21:46 98人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> const ...
- Codevs 1222 信与信封问题 二分图匹配,匈牙利算法
题目: http://codevs.cn/problem/1222/ 1222 信与信封问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 ...
随机推荐
- QSS 的选择器
本文连接地址:http://www.qtdebug.com/QSS-Selector.html 选择器决定了 style sheet 作用于哪些 Widget,QSS 支持 CSS2 定义的所有选择器 ...
- flask - 1
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, Worl ...
- 简单理解DES加密算法
数据加密标准(Data Encryption Standard,DES)是当前使用最广泛的加密体制,对于任意的加密方案,总有两个输入:明文和密钥. 明文是64bits,密钥是56bits 加密过程就是 ...
- io学习-相关文章
文章:IO编程 地址:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143 ...
- io学习2-磁盘阵列RAID
磁盘阵列 RAID(Redundant ArrayOf Inexpensive Disks) 如果你是一位数据库管理员或者经常接触服务器,那对RAID应该很熟悉了,作为最廉价的存储解决方案,RAID早 ...
- 甲级1002 A+B for Polynomials (25)
题目描述: This time, you are supposed to find A+B where A and B are two polynomials. Input Each input fi ...
- 淘宝RubyGems和NPM镜像的使用
题记:前不久在windows下配置jekyll环境时,需要用到gem,一个ruby的管理包,类似于管理nodejs包的npm.安装ruby环境后,使用gem安装包时请求国外的[https://ruby ...
- 【SSH】——使用ModelDriven的利与弊
在以往的web开发中,如果要在表单显示什么内容,我们就需要在Action中提前定义好表单显示的所有属性,以及一系列的get和set方法.如果实体类的属性非常多,那么Action中也要定义相同的属性.在 ...
- 解决Mysql错误Too many connections的方法
MySQL数据库 Too many connections出现这种错误明显就是 mysql_connect 之后忘记 mysql_close:当大量的connect之后,就会出现Too many co ...
- 将CRUD封装到一个工具类中
package org.zln.hibernate.utils; import org.hibernate.Session; import org.hibernate.SessionFactory; ...