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 题解 ...
随机推荐
- Linux-Shell脚本编程-学习-6-Shell编程-使用结构化命令-文件比较-case编程
这一片主要说test文件的比较,文件比较在日常使用的频率比较高,这里重点把每个部分都试着说说看 1. 检车目录 -d -d测试会检查指定的文件名是否在系统上以目录的形式存在,当我们要写文件到某个目录之 ...
- TTY锁屏与解锁
今天在tmux中使用vim时,不小心按了CTRL+S,结果整个vim不能使用了,在网上查到这里会有锁屏的问题,具体如下: 在tmux中,按CTRL+S,锁屏,按CTRL+Q,解锁.与系统的锁屏和解锁是 ...
- Linux编译安装opencv
参考https://blog.csdn.net/huang826336127/article/details/78760885 一.下载opencv源码包 下载地址:https://opencv.or ...
- DCGAN: "Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Network" Notes
- Alec Radford, ICLR2016 原文:https://arxiv.org/abs/1511.06434 论文翻译:https://www.cnblogs.com/lyrichu/p/ ...
- mongolass 中报 ($.content: "say Hi ~") ✖ (type: String)
第二次报这个错了, 一直以为MongoDB的模型用的type 是 String, 一直报错, 找不到原因. // 留言模型1 exports.Comment = mongolass.model('Co ...
- 预研报告——MyBatis持久层的demo
一.预研任务介绍和预研目标 任务介绍: 与 Hibernate 相比, MyBatis 是一个半自动化的持久层框架,以轻量级.效率高.原生代而好评如潮.虽然有在分享会上大致讲解,但是还是重新梳理成文字 ...
- BZOJ 3670 NOI2014 动物园 KMP+dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3670 题意概述:令num[i]表示字符串由1~i的字符形成的前缀中不相重叠的相同前后缀的数 ...
- cygwin上编译RPC框架thrift
cygwin的配置就不多说了,缺什么就通过安装器安装好了. 在thrift的官网下载 thrift-0.11.0源码,通过cmake编译,生成Makefile之后,make出现编译错误 /cygdri ...
- mysql与hive2.1.1安装和配置
1.mysql安装 这个安装很简单,是在线安装,只需要按顺序执行一下几个命令就ok了. (1)sudo apt-get install mysql-server (2)sudo apt-get ins ...
- C - 最长公共子序列
C - 最长公共子序列 Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem De ...