Hdu 2389 二分匹配
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): 823Problem DescriptionYou’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.
InputThe 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.OutputFor 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 Input2
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 4Sample OutputScenario #1:
2Scenario #2:
2
/*************************************************************************
> 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 二分匹配的更多相关文章
- hdu 4169 二分匹配最大独立集 ***
题意:有水平N张牌,竖直M张牌,同一方向的牌不会相交.水平的和垂直的可能会相交,求最少踢出去几张牌使剩下的牌都不相交. 二分匹配 最小点覆盖=最大匹配. 链接:点我 坐标点作为匹配的端点 #inclu ...
- hdu 5093 二分匹配
/* 题意:给你一些冰岛.公共海域和浮冰,冰岛可以隔开两个公共海域,浮冰无影响 求选尽可能多的选一些公共海域点每行每列仅能选一个. 限制条件:冰山可以隔开这个限制条件.即*#*可以选两个 预处理: * ...
- Battle ships HDU - 5093二分匹配
Battle shipsHDU - 5093 题目大意:n*m的地图,*代表海洋,#代表冰山,o代表浮冰,海洋上可以放置船舰,但是每一行每一列只能有一个船舰(类似象棋的車),除非同行或者同列的船舰中间 ...
- hdu 4685 二分匹配+强连通分量
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...
- H - Prince and Princess - HDU 4685(二分匹配+强连通分量)
题意:有N个王子M个公主,王子喜欢一些公主,而且只能是王子喜欢的人,他们才可以结婚,现在让他们尽可能多的结婚的前提下找出来每个王子都可以和谁结婚. 分析:先求出来他们的最大匹配,因为给的数据未必是完备 ...
- HDU 3729 二分匹配 反向匹配
题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定 点 ...
- HDU -1151 二分匹配与有向无环图不相交最小路径覆盖数
题意: 考虑一个小镇,那里的所有街道都是单向的,并且每条街道都从一个路口通往另一个路口.还众所周知,从一个十字路口开始,穿过城镇的街道,您将永远无法到达同一十字路口,即,城镇的街道没有环. 基于这些假 ...
- HDU 2603 二分匹配
#include <queue>#include <vector>#include <cstdio>#include <cstring>#include ...
- hdu 1528 二分匹配
#include<stdio.h> #include<string.h> int map[100][100],mark[100],link[100],max2,k; int f ...
随机推荐
- Spring MVC(十三)--保存并获取属性参数
这里的属性参数主要是指通过request.session.cookie等设置的属性,有时候我们需要将一些请求的参数保存到HTTP的request或者session对象中去,在控制器中也会进行设置和获取 ...
- svn both sides of the move must be committed together
从一个模块移动文件到另一个模块下,提交的时候报错. 选择2个模块工程,team-与资源库同步 选择2个模块下,2份文件,一份减号图标,一份加号图标,同时提交. 还有种情况,当你重名文件后,提交报错 打 ...
- Maven编译资源文件拷贝
<build> <finalName>op-balance-job-service</finalName> <plugins> <plugin&g ...
- windows API 第 18篇 FindFirstVolume FindNextVolume
函数定义:Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the vol ...
- HZOI2019 砍树 整除分块
题目链接:https://www.cnblogs.com/Juve/articles/11207540.html(密码你懂的)——————————>> 这题... 一开始想的二分,但此题不 ...
- js检测到如果是手机端就跳转到手机端的网址代码
if((/AppleWebKit.*Mobile/i.test(navigator.userAgent)||/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcat ...
- PHP--封装干净利落的输出dump()函数
/** * 打印函数 * */ if (! function_exists ( 'dump' )) { function dump($var, $exit = true) { echo '<pr ...
- IE6下extjs 弹窗不加载内容(无法执行内部js)的解决方案
//需要导入的文件,这里的路径需要些你自己的路径 <link rel="stylesheet" type="text/css" href="ex ...
- 关于 solusvm
1.母鸡用 fdisk 划一个独立分区出来与操作系统分开(分区标志 8e, 即 lvm),专门做vps磁盘,并做一个网桥2.母鸡安装被控端.注意:安装之前先安装 epel-release 源,并upd ...
- jeecms系统_自定义对象流程
库内新增对象Products 的流程说明: 第一步: com.jeecms.cms.entity.assist.base下建立模型基础类,BaseCmsProducts.java com.jeecms ...