poj 2536 GopherII(二分图匹配)
Description
The are n gophers and m gopher holes, each at distinct (x, y)
coordinates. A hawk arrives and if a gopher does not reach a hole in s
seconds it is vulnerable to being eaten. A hole can save at most one
gopher. All the gophers run at the same velocity v. The gopher family
needs an escape strategy that minimizes the number of vulnerable
gophers.
Input
input contains several cases. The first line of each case contains four
positive integers less than 100: n, m, s, and v. The next n lines give
the coordinates of the gophers; the following m lines give the
coordinates of the gopher holes. All distances are in metres; all times
are in seconds; all velocities are in metres per second.
Output
Sample Input
2 2 5 10
1.0 1.0
2.0 2.0
100.0 100.0
20.0 20.0
Sample Output
1 题目大意,有一块地上面有N只老鼠和M个只能装的下一只老鼠的老鼠洞,老鼠和老鼠洞的坐标已给出,老鹰在S秒后来到,老鼠的速度全部为V,问最少有多少老鼠来不及进洞
简单的二分图匹配算法,直接贴出代码:
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
int map[][],v[];
double x[],y[],xx,yy;
int match[];
int N,M,S,V;
double disIsOK(double x1,double y1,double x2,double y2){
return S*V>=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int dfs(int ii){
for(int i=;i<=N;i++){
if(map[i][ii]&&!v[i]){
v[i]=;
if(match[i]==||dfs(match[i])){
match[i]=ii;return ;
}
}
}
return ;
}
int main(){
while(cin>>N>>M>>S>>V){
memset(map,,sizeof(map));
memset(match,,sizeof(match));
for(int i=;i<=N;i++){
cin>>x[i]>>y[i];
}
for(int i=;i<=M;i++){
cin>>xx>>yy;
for(int j=;j<=N;j++){
if(disIsOK(x[j],y[j],xx,yy)){
map[j][i]=;
}
}
}
int res=;
for(int i=;i<=M;i++){
memset(v,,sizeof(v));
if(dfs(i))res++;
}
cout<<N-res<<endl;
}
return ;
}
结果截图:

poj 2536 GopherII(二分图匹配)的更多相关文章
- POJ 1274 裸二分图匹配
题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...
- POJ 2446 Chessboard (二分图匹配)
题意 在一个N*M的矩形里,用1*2的骨牌去覆盖该矩形,每个骨牌只能覆盖相邻的两个格子,问是否能把每个格子都盖住.PS:有K个孔不用覆盖. 思路 容易发现,棋盘上坐标和为奇数的点只会和坐标和为偶数的点 ...
- POJ 3041 Asteroids 二分图匹配
以行列为点建图,每个点(x,y) 对应一条边连接x,y.二分图的最小点覆盖=最大匹配 //#pragma comment(linker, "/STACK:1024000000,1024000 ...
- Poj(1274),二分图匹配
题目链接:http://poj.org/problem?id=1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Tota ...
- TTTTTTTTTTTTT poj 3057 Evacuation 二分图匹配+bfs
题意:见挑战230页 #include <iostream> #include <cstdio> #include <cstring> #include <c ...
- POJ 3057 Evacuation 二分图匹配
每个门每个时间只能出一个人,那就把每个门拆成多个,对应每个时间. 不断增加时间,然后增广,直到最大匹配. //#pragma comment(linker, "/STACK:10240000 ...
- POJ 2536 Gopher II (ZOJ 2536) 二分图匹配
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1882 http://poj.org/problem?id=2536 题目大 ...
- POJ 2195 Going Home (带权二分图匹配)
POJ 2195 Going Home (带权二分图匹配) Description On a grid map there are n little men and n houses. In each ...
- POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)
POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...
随机推荐
- bignum 大数模板
今天无意间看到一个很好的大数模板,能算加.减.乘.除等基本运算,但操作减法的时候只能大数减小数,也不支持负数,如果是两个负数的话去掉符号相加之后再取反就可以了,一正一负比较绝对值大小,然后相减.我借用 ...
- Maven——使用Nexus搭建Maven私服
原文:http://www.cnblogs.com/xdp-gacl/p/4068967.html Maven学习总结(九)--使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要 ...
- maven相关资料
http://www.yiibai.com/maven/ Maven教程 https://www.zhihu.com/question/20104270 http://huangnx.com/tags ...
- IE浏览器GET传参后台乱码
ie里面 get传递的字符串 为 gb2312 ,后台用的是utf-8类型 所以用 POST传递字符串到后端 否则进行js参数转码 encodeURI(""); 后端解码
- hiho_99_骑士问题
题目大意 给定国际象棋8x8棋盘上三个起始点,三个骑士分别从三个起始点开始移动(骑士只能走日字,且骑士从任意一点出发可以走遍整个棋盘).现要求三个骑士汇聚到棋盘上某个点,且使得骑士到达该点所移动的次数 ...
- 获取iframe外边数据
http://biancheng.dnbcw.info/javascript/178184.html
- sql cast()和convert()
19.CAST()函数和CONVERT()函数 CAST()函数可以将某种数据类型的表达式转化为另一种数据类型 CONVERT()函数也可以将制定的数据类型转换为另一种数据类型 19.1 CAST() ...
- php中的 == 和 ===
== 是等值 1 和 ‘1’ 是相等的 === 要等值并且类型相等,比如 1 和 ‘1’ 是不相等的,只有 ‘1’ 和 ‘1’ 是相等的.哈哈哈. http://ihacklog.com/post ...
- jsp 页面 jstl 日期的计算
1. <% page import ="java.util.Date"%> 2. <% Date date = new Date(); date = new Da ...
- html+asp.net上传文件
type="file" 的name以及id一定要写,并且名字相同 http://niunan.iteye.com/blog/479605 <form id="for ...