Gopher II
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6675   Accepted: 2732

Description

The gopher family, having averted the canine threat, must face a new predator.

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

The
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

Output consists of a single line for each case, giving the number of vulnerable gophers.

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(二分图最大匹配)的更多相关文章

  1. POJ2536 Gopher II(二分图最大匹配)

    Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9005   Accepted: 3724 Descrip ...

  2. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

  3. POJ 2584 T-Shirt Gumbo(二分图最大匹配)

    题意: 有五种衣服尺码:S,M,L,X,T N个人,每个人都有一个可以穿的衣服尺码的范围,例:SX,意思是可以穿S,M,L,X的衣服. 给出五种尺码的衣服各有多少件. 如果可以满足所有人的要求,输出 ...

  4. POJ 1463 Strategic game(二分图最大匹配)

    Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...

  5. 无题 II 二分图最大匹配

    题目描述 这是一个简单的游戏,在一个n*n的矩阵中,找n个数使得这n个数都在不同的行和列里并且要求这n个数中的最大值和最小值的差值最小. Input 输入一个整数T表示T组数据. 对于每组数据第一行输 ...

  6. poj 2724 Purifying Machine(二分图最大匹配)

    题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...

  7. poj 3020 Antenna Placement(二分图最大匹配)

    题意: N行M列的矩阵,每个格子里不是 * 就是 O . * :是一个利益点. O:是一个空白点. 每次可以用一个圈覆盖相邻的两个*.(左右相邻或上下相邻). 问最少需要多少个圈可以覆盖所有的*. 思 ...

  8. POJ 2536 Gopher II(二分图最大匹配)

    题意: N只地鼠M个洞,每只地鼠.每个洞都有一个坐标. 每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉. 规定每个洞最多只能藏一只地鼠. 问最少有多少 ...

  9. poj 2536 Gopher II (二分匹配)

    Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6345   Accepted: 2599 Descrip ...

随机推荐

  1. asp.net core mvc视频A:笔记3-5.视图数据共享之TempData

    前几节讲的都是单页面数据共享,从本节开始讲跨页面数据共享 创建项目3.5,新建控制器 代码 控制器 设置TempData 另一个视图中读取TempData数据 运行 此时如果刷新页面,页面中的内容“张 ...

  2. asp.net core mvc视频A:笔记3-1.视图基本用法

    常用介绍 注意:ViewBag是对View的封装,所以如果两者键值(Key)是一样的话,后者会覆盖前者. 新建项目,添加空控制器 小技巧-快速添加视图 控制器方法,使用ViewData和ViewBag ...

  3. free bsd x修改UTC->SCT

    #cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime #ntpdate asia.pool.ntp.org #adjkerntz -a #date

  4. 42:换汽水瓶ExchangeBottle

    有这样一道智力题:“某商店规定:三个空汽水瓶可以换一瓶汽水.小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?”答案是5瓶,方法如下:先用9个空瓶子换3瓶汽水,喝掉3瓶满的,喝完以后4个空瓶子,用3个 ...

  5. 压力测试工具集合(ab,webbench,Siege,http_load,Web Application Stress)

    压力测试工具集合(ab,webbench,Siege,http_load,Web Application Stress) 1 Apache附带的工具ab ab的全称是ApacheBench,是Apac ...

  6. 为什么阿里巴巴要求谨慎使用ArrayList中的subList方法

    GitHub 3.7k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 3.7k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 3.7k Star 的 ...

  7. 常见的C++数学计算库

    来源: https://blog.csdn.net/panhao762/article/details/55276811 作为理工科学生,想必有限元分析.数值计算.三维建模.信号处理.性能分析.仿真分 ...

  8. 【Github】之突然访问不了Github地址

    访问Github突然上不去了 解决办法: 一.修改hosts 1.打开Dns检测|Dns查询 - 站长工具2.在检测输入栏中输入http://github.com官网3.把检测列表里的TTL值最小的I ...

  9. 基于markdown的blog系统调研1:typecho

    ))

  10. java Collection-Map 之 TreeMap

    TreeMap 内部定义了一个类  static final class Entry<K,V> implements Map.Entry<K,V>,(自平衡红黑二叉树)作为数据 ...