[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 =============================以下是最小生成树+并 ...
随机推荐
- Windows Server 2008无法远程连接
Server 2008 R2依次配置好之后,重启发现总是远程桌面时而连接不上.具体现象如下: 偶尔可以通过桌面远程连接连接到Server.以为是防火墙的问题,各种设置——甚至关闭,依然无法连接.反复重 ...
- Concurrency and Application Design
Concurrency and Application Design In the early days of computing, the maximum amount of work per un ...
- scss基础
1.变量$ 全局 局部 .div{ $color:yellow; } 2.类似函数@mixin border-radius($radius) { }引用:@include border-radius( ...
- 北京Linux运维培训怎么选?
北京的地理优势和经济优势基本无需多言,作为全国机会最多的地方,吸引了无数的北漂前赴后继.作为中国互联网中心之一,北京有海量的运维岗位正在等待大家淘金.北京的Linux云计算培训业蓬勃发展. 云计算早已 ...
- 关于static关键字的思考
静态方法是否能调用非静态成员变量? static关键字具有如下特点: 一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象. 二.sta ...
- vue移动端地址三级联动组件(一)
vue移动端地区三级联动 省,市,县.用的vue+mintUi 因为多级联动以及地区的规则比较多.正好有时间自己写了一个.有问题以及建议欢迎指出.涉及到dom移动,所以依赖vue+jquery.这边数 ...
- Nginx反向代理WebSocket(WSS)
1. WebSocket协议 WebSocket 协议提供了一种创建支持客户端和服务端实时双向通信Web应用程序的方法.作为HTML5规范的一部分,WebSockets简化了开发Web实时通信程序的难 ...
- hdu 5171 GTY's birthday gift
GTY's birthday gift 问题描述 GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法k次 ...
- 简单的SpringBoot环境搭建
开始搭建前请确认您的计算机中的Maven已正确配置 一:使用IDEA创建一个Maven项目,图中第一个指针请选择自己正在使用的JDK版本,指针二请打勾,选中指针三所指向的类型并点击Next 二:填写G ...
- vue 实现点赞
在v-for循环里 <ul class="project_content"> <li v-for="(item, index) in items&quo ...