二分图的最大匹配

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. const int MAXN=;
  8. int nx,ny;
  9. int g[MAXN][MAXN];
  10. int cx[MAXN],cy[MAXN];
  11. int mk[MAXN];
  12. int n;
  13. double s,v;
  14. double H=1e-;
  15.  
  16. struct P
  17. {
  18. double x,y;
  19. } M[MAXN],D[MAXN];
  20.  
  21. int path(int u)
  22. {
  23. for(int v=; v<ny; v++)
  24. {
  25. if(g[u][v]&&!mk[v])
  26. {
  27. mk[v]=;
  28. if(cy[v]==-||path(cy[v]))
  29. {
  30. cx[u]=v;
  31. cy[v]=u;
  32. return ;
  33. }
  34. }
  35. }
  36. return ;
  37. }
  38.  
  39. int MaxMatch()
  40. {
  41. int res=;
  42. memset(cx,-,sizeof(cx));
  43. memset(cy,-,sizeof(cy));
  44. for(int i=; i<nx; i++)
  45. {
  46. if(cx[i]==-)
  47. {
  48. memset(mk,,sizeof(mk));
  49. res=res+path(i);
  50. }
  51. }
  52. return res;
  53. }
  54.  
  55. bool ok(const P&a,const P&b)
  56. {
  57. if(s*v-sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))>=H)
  58. return ;
  59. return ;
  60. }
  61.  
  62. int main()
  63. {
  64. int i,j;
  65. while(~scanf("%d%d%lf%lf",&nx,&ny,&s,&v))
  66. {
  67. memset(g,,sizeof(g));
  68. for(i=; i<nx; i++)
  69. scanf("%lf%lf",&M[i].x,&M[i].y);
  70. for(i=; i<ny; i++)
  71. scanf("%lf%lf",&D[i].x,&D[i].y);
  72. for(i=; i<nx; i++)
  73. for(j=; j<ny; j++)
  74. if(ok(M[i],D[j]))
  75. g[i][j]=;
  76. printf("%d\n",nx-MaxMatch());
  77. }
  78. return ;
  79. }

POJ 2536 Gopher II的更多相关文章

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

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

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

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

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

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

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

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

  5. [POJ 2536] Gopher ||

    [题目链接] http://poj.org/problem?id=2536 [算法] 匈牙利算法解二分图最大匹配 [代码] #include <algorithm> #include &l ...

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

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

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

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

  8. 2018.07.06 POJ2536 Gopher II(二分图匹配)

    Gopher II Time Limit: 2000MS Memory Limit: 65536K Description The gopher family, having averted the ...

  9. 二分图最大匹配(匈牙利算法) UVA 10080 Gopher II

    题目传送门 /* 匈牙利算法:这题比UVA_670简单,注意是要被吃的鼠的最少个数,套模板 */ #include <cstdio> #include <algorithm> ...

随机推荐

  1. js检测对象中是否存在某个属性

    1.使用in关键字.该方法可以判断对象的自有属性和继承来的属性是否存在. 2.使用对象的hasOwnProperty()方法.该方法只能判断自有属性是否存在,对于继承属性会返回false. 3.用un ...

  2. 用PhotoSwipe制作相册,手势可放大

    1.引入css和js <link href="css/photoswipee.css" rel="stylesheet" type="text/ ...

  3. vue 相对其他热门 框架 优点 --- 待续

    react vs  vue 1. 处理动画 vue 更有优势 , 这是由于 React 有大量的检查机制 2.性能更高, 在React中,你需要在每个地方去实现 shouldComponentUpda ...

  4. redis12--常用API

    上一篇总结我们使用我们本地的Eclipse中创建的jedis工程,链接到了我们处于VMware虚拟机上的Linux系统上的Redis服务,我们接下来讲一下jedis的一些常用的API.(1)jedis ...

  5. OGG中断后,重新同步操作

    模拟一下goldengata中断后,重新同步操作: 1.关掉源端抽取进程 GGSCI (20081122-2105) 15> info all Program Status Group Lag ...

  6. 【第四篇】Volley修改之GsonRequest

    json解析工具类的引入,这里引用lite马天宇的解析json的工具类: public class GsonImpl extends Json { private Gson gson = new Gs ...

  7. 手机端跳转和pc端跳转

    http://jingyan.baidu.com/article/cdddd41c61823e53cb00e198.html 参考网址 浏览:11532 | 更新:2014-04-22 16:51 第 ...

  8. hdu_5879_Cure(打表)

    题目链接:hdu_5879_Cure 题意: 给你一个n,让你计算1/k2的和,k从1到n. 题解: 因为只保留5位小数,所以打个100W的表,比这个数大的直接输出最后一位就行了 #include&l ...

  9. LeetCode OJ 121. Best Time to Buy and Sell Stock

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  10. chapter 12_1 数据文件

    Lua的一个重要特性,就是可以作为配置文件,利用到table构造式来定义一种文件格式. 只需要在写数据时做一点额外的工作,读取数据就会变得相当容易.也就是将数据作为Lua代码输出. 当运行这些代码时, ...