题目链接

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. eclipse memory analyzer对系统内存溢出堆文件解析0(转)

    前言 在平时工作过程中,有时会遇到OutOfMemoryError,我们知道遇到Error一般表明程序存在着严重问题,可能是灾难性的.所以找出是什么原因造成OutOfMemoryError非常重要.现 ...

  2. python3-常用模块之openpyxl(2)封装

    简单封装了下openpyxl,仅供参考,openpyxl版本2.6.2#操作存在的文件from openpyxl import Workbookfrom openpyxl import load_wo ...

  3. springboot拦截器的拦截配置和添加多个拦截器

    在spring2.0之前的版本大部分都采用extends WebMvcConfigurerAdapter,把拦截器配置成一个bean,具体的方法,我不细说,网上一大堆.而在spring2.0之后,这个 ...

  4. HBase 物理视图

  5. 性能压测中的SLA,你知道吗?

    本文是<Performance Test Together>(简称PTT)系列专题分享的第6期,该专题将从性能压测的设计.实现.执行.监控.问题定位和分析.应用场景等多个纬度对性能压测的全 ...

  6. [转]用HttpSessionListener与HttpSessionBindingListener实现在线人数统计

    原文链接:http://www.cnblogs.com/shencheng/archive/2011/01/07/1930227.html 下午比较闲(其实今天都很闲),想了一下在线人数统计方面的实现 ...

  7. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---观察者模式之WeatherReport[转]

      1   2{<HeadFirst设计模式>之观察者模式 }   3{ 主题与观察者                    }   4{ 编译工具 :Delphi7.0          ...

  8. mysql基础教程(一)-----概述、安装、查询

    概述 好处 •实现数据持久化 •使用完整的管理系统统一管理,易于查询 概念 DB 数据库(database):存储数据的“仓库”.它保存了一系列有组织的数据. DBMS 数据库管理系统(Databas ...

  9. stash解决git合并冲突问题

    参考博客: https://www.cnblogs.com/juandx/p/5362723.html

  10. 安装springsource-tool-suite插件成功之后找不到spring的处理办法

    最近学习spring,安装springsource-tool-suite插件,成功之后,在help-installation details里面可以找到安装的spring插件,却在window-pre ...