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 ...
随机推荐
- Mybatis调用Mysql存储过程
在我的后台系统中,今天需要使用到存储过程.存储过程还真没写过,今天就写了个存储过程.使用在后台中. 其实这个接口功能 是涉及几张表的修改,删除,新增的.就写个一个存储过程. 存储过程: ), ),) ...
- What is the difference between extensibility and scalability?
You open a small fast food center, with a serving capacity of 5-10 people at a time. But you have en ...
- 转自“脚本之家”!!JDBC之PreparedStatement类中预编译的综合应用解析
JDK 文档:SQL 语句被预编译并存储在 PreparedStatement 对象中(PreparedStatement是存储在JDBC里的,初始化后,缓存到了JDBC里),然后可以使用此对象多次高 ...
- maven寻找jar
http://mvnrepository.com/artifact/org.springframework/spring-context
- sccm部署win7原版系统系统盘为D盘
1. 系统部署完毕之后是这样的
- MySQL锁监视器
还在为看不懂何登成的加锁处理分析文章感到羞愧吗? 还在因为何大师的笔误,陷入深深的迷茫吗? 只要你拥有大于5.6.16版本的MySQL,锁监视器你值得拥有! 快速入门 开启 set GLOBAL in ...
- Ubuntu 修复windows启动项
打开终端输入命令sudo gedit /etc/default/grub修改GRUB_TIMEOUT="10"然后在终端中输入sudo update-grubupdate 命令会自 ...
- nodeschool.io 10
~~ TIME SERVER ~~ Write a TCP time server! Your server should listen to TCP connections on port 8000 ...
- ios基础篇(八)——UITabBarController的简单介绍
一.简介 UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就 ...
- python的一点小常识
在Python中,有两种变长参数,分别是元组(非关键字参数)和字典(关键字参数),其参数以一个*开头表示任意长度的元组[tuple],可以接收连续一串参数,参数以两个*开头表示一个字典[dict],即 ...