[POJ 2536] Gopher ||
[题目链接]
http://poj.org/problem?id=2536
[算法]
匈牙利算法解二分图最大匹配
[代码]
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 110 int i,j,n,m,s,v,tot,ans;
pair<double,double> a[MAXN],b[MAXN];
int head[MAXN],match[MAXN << ];
bool visited[MAXN << ]; struct edge
{
int to,nxt;
} e[MAXN * MAXN];
inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
}
inline double dist(pair<double,double> a,pair<double,double> b)
{
return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
inline bool hungary(int u)
{
int i,v;
visited[u] = true;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!visited[v])
{
visited[v] = true;
if (!match[v] || hungary(match[v]))
{
match[v] = u;
return true;
}
}
}
return false;
} int main()
{ while (scanf("%d%d%d%d",&n,&m,&s,&v) != EOF)
{
tot = ;
memset(head,,sizeof(head));
memset(match,,sizeof(match));
for (i = ; i <= n; i++) scanf("%lf%lf",&a[i].first,&a[i].second);
for (i = ; i <= m; i++) scanf("%lf%lf",&b[i].first,&b[i].second);
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
if (1.0 * dist(a[i],b[j]) / v <= 1.0 * s)
addedge(i,j + n);
}
}
ans = ;
for (i = ; i <= n; i++)
{
memset(visited,false,sizeof(visited));
if (hungary(i)) ans++;
}
printf("%d\n",n - ans);
} return ; }
[POJ 2536] Gopher ||的更多相关文章
- POJ 2536 Gopher II (ZOJ 2536) 二分图匹配
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1882 http://poj.org/problem?id=2536 题目大 ...
- POJ 2536 Gopher II(二分图的最大匹配)
题目链接:http://poj.org/problem?id=2536 题意:已知有n仅仅老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一仅仅老鹰要吃老鼠,问有多少个老鼠被吃. 非常明晰,二 ...
- poj 2536 Gopher II (二分匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6345 Accepted: 2599 Descrip ...
- POJ 2536 Gopher II
二分图的最大匹配 地鼠内部和地鼠洞内部都是没有边相连的,那么就可以看成一个二分图.地鼠如果可以跑到那个地鼠洞,就连一条边,然后跑二分图的最大匹配,最后地鼠的数量减去最大匹配数就是答案. #includ ...
- POJ 2536 Gopher II(二分图最大匹配)
题意: N只地鼠M个洞,每只地鼠.每个洞都有一个坐标. 每只地鼠速度一样,对于每只地鼠而言,如果它跑到某一个洞的所花的时间小于等于S,它才不会被老鹰吃掉. 规定每个洞最多只能藏一只地鼠. 问最少有多少 ...
- POJ 2536 之 Gopher II(二分图最大匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6675 Accepted: 2732 Descrip ...
- poj 2536 GopherII(二分图匹配)
Description The gopher family, having averted the canine threat, must face a new predator. The are n ...
- POJ 2536 匈牙利算法
思路:最大匹配 (很裸) // by SiriusRen #include <cmath> #include <cstdio> #include <cstring> ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- canves图形变换
canves用得好可以有好多效果: html:<canvas id="myCanvas" width="700" height="300&quo ...
- JS——拖拽盒子
注意事项: 1.opacity是全部元素变透明,rgba只是背景色变透明 2.先是注册鼠标按下的事件,此时就需要记录鼠标在盒子中的坐标 3.再在鼠标按下事件中注册鼠标移动事件,此时鼠标的坐标是不断变化 ...
- JS——绑定自定义属性
1.绑定自定义属性: (1)元素节点.属性或元素节点[属性]绑定的属性不会出现在标签中,setAttribute可以出现在标签中. (2)setAttribute获取不到元素节点.属性形式绑定的属性值 ...
- 2015.12.20-2015.12.25 大论文迭代 A
进一步充实大论文内容.结构,完善一遍大论文 12.20周天,完成论文第五章总结部分,和第一章的修改 12.21周一,完成论文第二章的修改充实 12.22周二,完成论文第三章的修改充实 12.23周三, ...
- (转)OL2中设置鼠标的样式
http://blog.csdn.net/gisshixisheng/article/details/49496289 概述: 在OL2中,鼠标默认是箭头,地图移动时,鼠标样式是移动样式:很多时候,为 ...
- android Adapter总结
1.连接视图与数据.数据封装: 2.视图构造与配置: 3.数据更新监听: 4.视图重用机制. * An Adapter object acts as a bridge between an {@lin ...
- 9 Java 堆排序
堆是具有以下性质的完全二叉树,每个结点的值都大于或等于其左右孩子结点的值,称为大顶堆:或者每个结点的值都小于或等于其左右孩子结点的值,称为小顶堆.如下图: 同时,我们对堆中的结点按层进行编号,将这种逻 ...
- LINUX-查看进程内环境变量
ps -ef find PID cat /proc/$PID/environ | grep ENV
- c#用控制台程序安装启动停止卸载服务
第一步:新建控制台项目 第二步:添加服务 第三步:右键新建完成的服务项 点击 在start 和stop事件中分别写上 第四步 编写代码 双击打开 using System; using Syst ...
- 【XSY3413】Lambda - 造计算机初步——邱奇-图灵论题与lambda演算
题意: 关于邱奇-图灵论题的一点思考 这道题起源于计算机科学史上一个非常著名的问题——邱奇-图灵论题,这个论题是可计算性理论的基石,关于它的思考与证明几乎贯穿了整个计算机科学史,涵盖了数学.算法理论. ...