POJ 2536 之 Gopher II(二分图最大匹配)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 6675 | Accepted: 2732 |
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
算法分析:开始的时候很脑残,想出来的算法是贪心的策略,虽然不知是否可行,
但我的贪心策略是这样的:让每一只地鼠钻进它所能到达的最远的洞,也就是说呢,
让每一只地鼠尽可能的跑远点再钻洞。在我代码实现的过程中发现很麻烦!要记录每只
地鼠到达其他洞口的距离 还要排序什么的!非常的麻烦,并且还不知道最后的结果是否正确。 后来想到了,刚学的“二分图的最大匹配算法”,这时候的算法思想是:把读入的 每只地鼠的坐标 去计算和到其它每一个洞口的“距离”
看是否在可达的范围内,若可达,证明“该地鼠” 和 “该洞口”存在关系, 对应的map[][]标记为1。剩下的dfs. (说白了就是二分
图的模板问题)。
#include <math.h>
#include <stdio.h>
#include <string.h> int n, m;
double s, v; struct N //记录地鼠的坐标
{
double x;
double y;
}q[]; struct node //记录鼠洞的坐标
{
double x;
double y;
}w[]; int map[][];
int vt[];
int link[]; int dfs(int dd)
{
int i;
for(i=; i<m; i++)
{
if(map[dd][i]== && vt[i]== )
{
vt[i]=;
if(link[i]==- || dfs(link[i]))
{
link[i]=dd;
return ;
}
}
}
return ;
} int main()
{
int i, j, k;
double dis;
double gg;
while(scanf("%d %d %lf %lf", &n, &m, &s, &v)!=EOF )
{
for(i=; i<n; i++)
{
scanf("%lf %lf", &q[i].x, &q[i].y );
}
for(i=; i<m; i++)
{
scanf("%lf %lf", &w[i].x, &w[i].y );
}
gg = s * v;
memset(map, , sizeof(map));
memset(link, -, sizeof(link)); for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
dis = sqrt( (w[j].x-q[i].x)*(w[j].x-q[i].x) + (w[j].y-q[i].y)*(w[j].y-q[i].y) );
if(dis<=gg)
{
map[i][j] = ;
}
}
}
int cnt=;
for(i=; i<n; i++)
{
memset(vt, , sizeof(vt));
cnt+=dfs(i);
}
printf("%d\n", n-cnt );
}
return ;
}
POJ 2536 之 Gopher II(二分图最大匹配)的更多相关文章
- POJ2536 Gopher II(二分图最大匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9005 Accepted: 3724 Descrip ...
- [POJ] 1274 The Perfect Stall(二分图最大匹配)
题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...
- POJ 2584 T-Shirt Gumbo(二分图最大匹配)
题意: 有五种衣服尺码:S,M,L,X,T N个人,每个人都有一个可以穿的衣服尺码的范围,例:SX,意思是可以穿S,M,L,X的衣服. 给出五种尺码的衣服各有多少件. 如果可以满足所有人的要求,输出 ...
- POJ 1463 Strategic game(二分图最大匹配)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- 无题 II 二分图最大匹配
题目描述 这是一个简单的游戏,在一个n*n的矩阵中,找n个数使得这n个数都在不同的行和列里并且要求这n个数中的最大值和最小值的差值最小. Input 输入一个整数T表示T组数据. 对于每组数据第一行输 ...
- poj 2724 Purifying Machine(二分图最大匹配)
题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...
- poj 3020 Antenna Placement(二分图最大匹配)
题意: N行M列的矩阵,每个格子里不是 * 就是 O . * :是一个利益点. O:是一个空白点. 每次可以用一个圈覆盖相邻的两个*.(左右相邻或上下相邻). 问最少需要多少个圈可以覆盖所有的*. 思 ...
- POJ 2536 Gopher II(二分图最大匹配)
题意: N只地鼠M个洞,每只地鼠.每个洞都有一个坐标. 每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉. 规定每个洞最多只能藏一只地鼠. 问最少有多少 ...
- poj 2536 Gopher II (二分匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6345 Accepted: 2599 Descrip ...
随机推荐
- Android适配方案小结(二)
该节主要记录从代码中获取与屏幕适配相关的各个參数: Java代码例如以下 public class ScreenUtil { /** * Note: * 仅仅有activity能够使用getWindo ...
- 使用程序修改系统(IE)代理设置
文章都是发布在github再转到这边的,这边格式可能会乱掉.博客地址:benqy.com 这是本人在做的一个前端开发调试工具(HttpMock),功能是web服务器+http日记+http代理(类似f ...
- 我佩服-WPF(2)
简单的学学WPF,我们知道他就是拖拉控件,一点也不难.假设公司真的使用WPF搞开发,你去面试,直接说WPF就是拖拉控件,那就慘了. 有些公司非常喜欢使用WPF.不不过比較简单.更重要的是全然做到了分离 ...
- scala 编写wordCount
加载文件 scala> var f1=sc.textFile("/tmp/dataTest/followers.txt") scala> f1.flatMap(x=&g ...
- Android linux kernel privilege escalation vulnerability and exploit (CVE-2014-4322)
In this blog post we'll go over a Linux kernel privilege escalation vulnerability I discovered which ...
- git 修改远程仓库地址
以前的老项目需要修改git路径,为了保留之前的上传记录和分支等可以通过以下方法解决这个问题 sourceTree项目远程仓库,直接修改origin路径,然后提交一个commit即可将项目上传到新的gi ...
- Android Studio 使用笔记:在图形界面使用 Gradle 配置项目所需jar包
在 Android Studio 中使用第三方 jar 包,可以直接下载后添加到项目中,也可以使用 Gradle 配置进行管理.图形界面下十分简单. 点击下图中间的图标,或者选中 Model ,按F4 ...
- LNMP环境搭建之php安装,wordpress博客搭建
LNMP环境搭建之php安装,wordpress博客搭建 一.介绍: 1.什么是CGI CGI全称是"通用网关接口"(Common Gateway Interface),HTTP服 ...
- Android中应用安装分析
#1 安装方式 1 安装系统APK和预制APK时,通过PMS的构造函数中安装,即第一次开机时安装应用,没有安装界面. 2 网络下载安装,通过应用商店等,即调用PackageManager.instal ...
- [ACM] POJ 3740 Easy Finding (DLX模板题)
Easy Finding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16178 Accepted: 4343 Des ...