题目链接

Rain on your Parade

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

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

 题目也是很裸的最大匹配问题,匈牙利算法复杂度太高(对于这题而言, O(n*m)), 而Hopcroft-Karp算法复杂度只有O(sqrt(n)*m).关于算法的具体实现,
网上百度一大推。1A......:D
Accepted Code:
 /*************************************************************************
> File Name: 2389.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月01日 星期五 22时08分50秒
> Propose: Hopcroft-Karp
************************************************************************/
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f3f;
int cx[maxn], cy[maxn];
int dx[maxn], dy[maxn];
bool mark[maxn];
vector<int> next[maxn];
int n, m;
struct node {
int x, y, s;
}g[maxn]; int dist(int x1, int y1, int x2, int y2) {
return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
} int searchPath() {
memset(dx, -, sizeof(dx));
memset(dy, -, sizeof(dy));
queue<int> Q;
for (int i = ; i <= m; i++) if (cx[i] == -) {
dx[i] = ;
Q.push(i);
}
int dist = INF;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
if (dx[u] > dist) break;
for (int i = ; i < (int)next[u].size(); i++) {
int v = next[u][i];
if (dy[v] == -) {
dy[v] = dx[u] + ;
if (cy[v] == -) {
dist = dy[v];
} else {
dx[cy[v]] = dy[v] + ;
Q.push(cy[v]);
}
}
}
}
return dist != INF;
} int findPath(int u) {
for (int i = ; i < (int)next[u].size(); i++) {
int v = next[u][i];
if (!mark[v] && dy[v] == dx[u] + ) {
mark[v] = true;
if (cy[v] == - || findPath(cy[v])) {
cy[v] = u;
cx[u] = v;
return ;
}
}
}
return ;
} int MaxMatch() {
int res = ;
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
while (searchPath()) {
memset(mark, false, sizeof(mark));
for (int i = ; i <= m; i++) {
if (cx[i] == -) {
res += findPath(i);
}
}
}
return res;
} int main(void) {
int T, cas = ;
scanf("%d", &T);
while (T--) {
int t;
scanf("%d", &t);
scanf("%d", &m);
for (int i = ; i <= m; i++) {
next[i].clear();
scanf("%d %d %d", &g[i].x, &g[i].y, &g[i].s);
}
scanf("%d", &n);
for (int i = ; i <= n; i++) {
int x, y;
scanf("%d %d", &x, &y);
for (int j = ; j <= m; j++) {
if (t*t*g[j].s*g[j].s >= dist(x, y, g[j].x, g[j].y)) {
next[j].push_back(i);
}
}
}
printf("Scenario #%d:\n%d\n\n", cas++, MaxMatch());
} return ;
}

Hdu 2389 二分匹配的更多相关文章

  1. hdu 4169 二分匹配最大独立集 ***

    题意:有水平N张牌,竖直M张牌,同一方向的牌不会相交.水平的和垂直的可能会相交,求最少踢出去几张牌使剩下的牌都不相交. 二分匹配 最小点覆盖=最大匹配. 链接:点我 坐标点作为匹配的端点 #inclu ...

  2. hdu 5093 二分匹配

    /* 题意:给你一些冰岛.公共海域和浮冰,冰岛可以隔开两个公共海域,浮冰无影响 求选尽可能多的选一些公共海域点每行每列仅能选一个. 限制条件:冰山可以隔开这个限制条件.即*#*可以选两个 预处理: * ...

  3. Battle ships HDU - 5093二分匹配

    Battle shipsHDU - 5093 题目大意:n*m的地图,*代表海洋,#代表冰山,o代表浮冰,海洋上可以放置船舰,但是每一行每一列只能有一个船舰(类似象棋的車),除非同行或者同列的船舰中间 ...

  4. hdu 4685 二分匹配+强连通分量

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...

  5. H - Prince and Princess - HDU 4685(二分匹配+强连通分量)

    题意:有N个王子M个公主,王子喜欢一些公主,而且只能是王子喜欢的人,他们才可以结婚,现在让他们尽可能多的结婚的前提下找出来每个王子都可以和谁结婚. 分析:先求出来他们的最大匹配,因为给的数据未必是完备 ...

  6. HDU 3729 二分匹配 反向匹配

    题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定  点 ...

  7. HDU -1151 二分匹配与有向无环图不相交最小路径覆盖数

    题意: 考虑一个小镇,那里的所有街道都是单向的,并且每条街道都从一个路口通往另一个路口.还众所周知,从一个十字路口开始,穿过城镇的街道,您将永远无法到达同一十字路口,即,城镇的街道没有环. 基于这些假 ...

  8. HDU 2603 二分匹配

    #include <queue>#include <vector>#include <cstdio>#include <cstring>#include ...

  9. hdu 1528 二分匹配

    #include<stdio.h> #include<string.h> int map[100][100],mark[100],link[100],max2,k; int f ...

随机推荐

  1. java单元测试小结

    1. mock 构造函数 import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; im ...

  2. linux最基础最常用的命令快速手记 — 让手指跟上思考的速度(三)

    这一篇作为姐妹篇的第三篇,废话不多说,我觉得这个比mysql的还要重要,为什么,一旦你摊上linux 敲键盘输入命令简直是要飞的速度,不断的卡壳查命令,效率太低了,而且非常严重的影响思绪,思绪! 某些 ...

  3. rabbitmq类

    1.accept.php消费者代码需要在命令行执行 2.'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码 RabbitMQCommand ...

  4. C++与Matlab混合编程之:矩阵数据结构

    项目需要将matlab代码写成C++,准备用opencv.opencv中矩阵的存储与matlab有所不同,应注意以下问题: 1.matlab中矩阵是按照列优先存储的.对于n0*n1*...*nn维的矩 ...

  5. LUOGU P4113 [HEOI2012]采花

    传送门 解题思路 莫队题卡莫队...莫队只能拿到100分,满分200.正解主席树??发个莫队100分代码. 代码 #include<iostream> #include<cstdio ...

  6. utils03_clone远程仓库

    1.Bash here 克隆方式 复制要克隆远程仓库的SSH或者HTTPS 使用Bash here克隆文件 2.使用git同步

  7. jaxFileUpload插件异步上传图片

    第一步:引入jquery文件和jaxFileUpload文件 文件位置:https://pan.baidu.com/s/1jHEyIyy 第二步,前端: <div class="for ...

  8. TFS2013 微软源代码管理工具 安装与使用图文教程

    最近公司新开发一个项目要用微软的TFS2013进行项目的源代码管理,以前只是用过SVN,从来没有用过TFS,所以在网上百度.谷歌了好一阵子来查看怎么安装和配置,还好花了一天时间总算是初步的搞定了,下面 ...

  9. 在sqlserver 的函数或存储过程中抛出异常(raiserror )

      raiserror的作用: raiserror 是用于抛出一个错误 其语法如下: RAISERROR ( { msg_id | msg_str | @local_variable } { ,sev ...

  10. CSS3属性transform详解【转载】

    CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)   在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾 ...