[题目链接]

http://poj.org/problem?id=2536

[算法]

匈牙利算法解二分图最大匹配

[代码]

  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cctype>
  4. #include <cerrno>
  5. #include <clocale>
  6. #include <cmath>
  7. #include <complex>
  8. #include <cstdio>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <ctime>
  12. #include <deque>
  13. #include <exception>
  14. #include <fstream>
  15. #include <functional>
  16. #include <limits>
  17. #include <list>
  18. #include <map>
  19. #include <iomanip>
  20. #include <ios>
  21. #include <iosfwd>
  22. #include <iostream>
  23. #include <istream>
  24. #include <ostream>
  25. #include <queue>
  26. #include <set>
  27. #include <sstream>
  28. #include <stdexcept>
  29. #include <streambuf>
  30. #include <string>
  31. #include <utility>
  32. #include <vector>
  33. #include <cwchar>
  34. #include <cwctype>
  35. #include <stack>
  36. #include <limits.h>
  37. using namespace std;
  38. #define MAXN 110
  39.  
  40. int i,j,n,m,s,v,tot,ans;
  41. pair<double,double> a[MAXN],b[MAXN];
  42. int head[MAXN],match[MAXN << ];
  43. bool visited[MAXN << ];
  44.  
  45. struct edge
  46. {
  47. int to,nxt;
  48. } e[MAXN * MAXN];
  49. inline void addedge(int u,int v)
  50. {
  51. tot++;
  52. e[tot] = (edge){v,head[u]};
  53. head[u] = tot;
  54. }
  55. inline double dist(pair<double,double> a,pair<double,double> b)
  56. {
  57. return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
  58. }
  59. inline bool hungary(int u)
  60. {
  61. int i,v;
  62. visited[u] = true;
  63. for (i = head[u]; i; i = e[i].nxt)
  64. {
  65. v = e[i].to;
  66. if (!visited[v])
  67. {
  68. visited[v] = true;
  69. if (!match[v] || hungary(match[v]))
  70. {
  71. match[v] = u;
  72. return true;
  73. }
  74. }
  75. }
  76. return false;
  77. }
  78.  
  79. int main()
  80. {
  81.  
  82. while (scanf("%d%d%d%d",&n,&m,&s,&v) != EOF)
  83. {
  84. tot = ;
  85. memset(head,,sizeof(head));
  86. memset(match,,sizeof(match));
  87. for (i = ; i <= n; i++) scanf("%lf%lf",&a[i].first,&a[i].second);
  88. for (i = ; i <= m; i++) scanf("%lf%lf",&b[i].first,&b[i].second);
  89. for (i = ; i <= n; i++)
  90. {
  91. for (j = ; j <= m; j++)
  92. {
  93. if (1.0 * dist(a[i],b[j]) / v <= 1.0 * s)
  94. addedge(i,j + n);
  95. }
  96. }
  97. ans = ;
  98. for (i = ; i <= n; i++)
  99. {
  100. memset(visited,false,sizeof(visited));
  101. if (hungary(i)) ans++;
  102. }
  103. printf("%d\n",n - ans);
  104. }
  105.  
  106. return ;
  107.  
  108. }

[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. Windows Server 2008无法远程连接

    Server 2008 R2依次配置好之后,重启发现总是远程桌面时而连接不上.具体现象如下: 偶尔可以通过桌面远程连接连接到Server.以为是防火墙的问题,各种设置——甚至关闭,依然无法连接.反复重 ...

  2. Concurrency and Application Design

    Concurrency and Application Design In the early days of computing, the maximum amount of work per un ...

  3. scss基础

    1.变量$ 全局 局部 .div{ $color:yellow; } 2.类似函数@mixin border-radius($radius) { }引用:@include border-radius( ...

  4. 北京Linux运维培训怎么选?

    北京的地理优势和经济优势基本无需多言,作为全国机会最多的地方,吸引了无数的北漂前赴后继.作为中国互联网中心之一,北京有海量的运维岗位正在等待大家淘金.北京的Linux云计算培训业蓬勃发展. 云计算早已 ...

  5. 关于static关键字的思考

    静态方法是否能调用非静态成员变量?    static关键字具有如下特点:        一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象.        二.sta ...

  6. vue移动端地址三级联动组件(一)

    vue移动端地区三级联动 省,市,县.用的vue+mintUi 因为多级联动以及地区的规则比较多.正好有时间自己写了一个.有问题以及建议欢迎指出.涉及到dom移动,所以依赖vue+jquery.这边数 ...

  7. Nginx反向代理WebSocket(WSS)

    1. WebSocket协议 WebSocket 协议提供了一种创建支持客户端和服务端实时双向通信Web应用程序的方法.作为HTML5规范的一部分,WebSockets简化了开发Web实时通信程序的难 ...

  8. hdu 5171 GTY's birthday gift

    GTY's birthday gift 问题描述 GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法k次 ...

  9. 简单的SpringBoot环境搭建

    开始搭建前请确认您的计算机中的Maven已正确配置 一:使用IDEA创建一个Maven项目,图中第一个指针请选择自己正在使用的JDK版本,指针二请打勾,选中指针三所指向的类型并点击Next 二:填写G ...

  10. vue 实现点赞

    在v-for循环里 <ul class="project_content"> <li v-for="(item, index) in items&quo ...