[题目链接]

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 ||的更多相关文章

  1. POJ 2536 Gopher II (ZOJ 2536) 二分图匹配

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1882 http://poj.org/problem?id=2536 题目大 ...

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

    题目链接:http://poj.org/problem?id=2536 题意:已知有n仅仅老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一仅仅老鹰要吃老鼠,问有多少个老鼠被吃. 非常明晰,二 ...

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

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

  4. POJ 2536 Gopher II

    二分图的最大匹配 地鼠内部和地鼠洞内部都是没有边相连的,那么就可以看成一个二分图.地鼠如果可以跑到那个地鼠洞,就连一条边,然后跑二分图的最大匹配,最后地鼠的数量减去最大匹配数就是答案. #includ ...

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

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

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

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

  7. poj 2536 GopherII(二分图匹配)

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

  8. POJ 2536 匈牙利算法

    思路:最大匹配 (很裸) // by SiriusRen #include <cmath> #include <cstdio> #include <cstring> ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. Python常用的标准库及第三方库

    标准库Python拥有一个强大的标准库.Python语言的核心只包含数字.字符串.列表.字典.文件等常见类型和函数,而由Python标准库提供了系统管理.网络通信.文本处理.数据库接口.图形系统.XM ...

  2. POJ_3013_最短路

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 23630   Accepted: 5 ...

  3. NSOperationQueue和GCD的区别,以及在什么场合下使用

    1> GCD是纯C语言的API .NSOperationQueue是基于GCD的OC的封装. 2> GCD只支持FIFO队列,NSOperationQueue可以方便设置执行顺序,设置最大 ...

  4. 删除Git服务器文件但是保留本地文件

    参考: https://blog.csdn.net/u012804886/article/details/83059315 https://www.cnblogs.com/wfsovereign/p/ ...

  5. BeginEditorCommand()

    BeginEditorCommand();开始把焦点给CAD CompleteEditorCommand();焦点给窗体

  6. Linux cat 命令

    cat命令是linux下的一个文本输出命令,通常是用于观看某个文件的内容的:cat主要有三大功能:1.一次显示整个文件.$ cat   filename2.从键盘创建一个文件.$ cat  >  ...

  7. win10如何进入安全模式的几种方法

    首先,说一下安全模式的作用: 安全模式, 用途有很多,常见的作用有以下几点 1. 电脑可能由于安装了某些驱动或者软件,不兼容导致电脑启动不了,可以进入安全模式卸载 2. 电脑中病毒之后,可以进入安全模 ...

  8. Pyhon信息采集 - 喜马拉雅专辑歌曲

    目录 Pyhon信息采集 - 喜马拉雅专辑歌曲 Pyhon信息采集 - 喜马拉雅专辑歌曲 setting.py # 喜马拉雅URL XMLY_URL = "https://www.ximal ...

  9. 在Docker上构建mysql容器

    1.查看docker上的镜像是否有 mysql,如果没有下载则列表中没有  [root@holly holly]# docker images; 如果没有只会看到如下结构 REPOSITORY  TA ...

  10. tipsText表单验证(注册)

    注册表单验证脚本 <script src="/assets/skins/js/jquery-1.11.2.min.js"></script> <scr ...