题目链接

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. 05-4-style的代替操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 史上最贵域名诞生!360斥资1700万美元买360.com

    昨日,360公司官方人士向腾讯科技确认,公司已斥巨资收购国际顶级域名360.com.传闻这一收购价格为1700万美元,约合人民币1.1亿元. 史上最贵域名诞生!360斥资1700万美元买360.com ...

  3. Reflections框架,类扫描工具

    Reflections是一个能提供一站式服务的对象. 巧用Reflections库实现包扫描(扫描某个包中某个接口实现.注解等) 它扫描工程的classpath,为元数据建索引,允许你运行时查询元数据 ...

  4. javascript执行上下文和变量对象

    执行上下文(execution context): 执行上下文就是当前 JavaScript 代码被解析和执行时所在环境的抽象概念. js语言是一段一段的顺序执行,这个“段”其实就是我们说的这个执行上 ...

  5. Leetcode145. Binary Tree Postorder Traversal二叉树的后序遍历

    给定一个二叉树,返回它的 后序 遍历. 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 递归: class Solution { public: vector<int> res; ve ...

  6. 如何正确使用 Flink Connector?

    本文主要分享 Flink connector 相关内容,分为以下三个部分的内容:第一部分会首先介绍一下 Flink Connector 有哪些.第二部分会重点介绍在生产环境中经常使用的 kafka c ...

  7. svn 设置快捷命令

    # some more svn aliases alias svnset='svn propset svn:externals . -F' alias svnget='svn propget svn: ...

  8. Python-基本文件处理

    目录 文件的类型 什么是文件? 文件的分类 文件的打开与关闭 文件处理的三个步骤 使用方式 爬虫 requests库的使用 文件的类型 什么是文件? 一堆.py/.txt 存储着文字信息文件, 文件的 ...

  9. Nginx 的常用命令

    nginx命令,先来一波基本操作: start nginx // 启动Nginx nginx -t // 测试配置文件 nginx -v // 查看Nginx版本 nginx -V // 查看Ngin ...

  10. day67test

    作业 1.按照上方 知识点总结 模块,总结今天所学知识点: 2.有以下广告数据(实际数据命名可以略做调整) ad_data = { tv: [ {img: 'img/tv/001.png', titl ...