题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=516

Your old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his great-great-uncle
decided to divide the land into a grid of small squares. He turned some of the squares into ponds, for he loved to hunt ducks and wanted to attract them to his property. (You cannot be sure, for you have not been to the place, but he may have made so many
ponds that the land may now consist of several disconnected islands.)



Your uncle Tom wants to sell the inherited land, but local rules now regulate property sales. Your uncle has been informed that, at his great-great-uncle's request, a law has been passed which establishes that property can only be sold in rectangular lots the
size of two squares of your uncle's property. Furthermore, ponds are not salable property.



Your uncle asked your help to determine the largest number of properties he could sell (the remaining squares will become recreational parks).

Input



Input will include several test cases. The first line of a test case contains two integers N and M, representing, respectively, the number of rows and columns of the land (1 <= N, M <= 100). The second line will contain an integer K indicating the number of
squares that have been turned into ponds ( (N x M) - K <= 50). Each of the next K lines contains two integers X and Y describing the position of a square which was turned into a pond (1 <= X <= N and 1 <= Y <= M). The end of input is indicated by N = M = 0.

Output



For each test case in the input your program should produce one line of output, containing an integer value representing the maximum number of properties which can be sold.

Sample Input

4 4

6

1 1

1 4

2 2

4 1

4 2

4 4

4 3

4

4 2

3 2

2 2

3 1

0 0

Sample Output

4

3


Source: South America 2002, Practice

题意:

有N * N 的土地,当中某些点被挖成池塘了,其余的地方为空地,

如今要分成 1 * 2 的空地来出售,

求最大能出售的数量。

PS:

把每块土地和他的上下左右建边!

代码例如以下:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. using namespace std;
  6.  
  7. //顶点编号从1開始的
  8. #define MAXN 117
  9. int LN, RN;//L,R数目
  10. int g[MAXN][MAXN], linker[MAXN];
  11. bool used[MAXN];
  12. int vis[MAXN][MAXN], a[MAXN][MAXN];
  13. int dirx[4] = {0,0,1,-1};
  14. int diry[4] = {1,-1,0,0};
  15. int dfs(int L)//从左边開始找增广路径
  16. {
  17. int R;
  18. for(R = 1; R <= RN; R++)
  19. {
  20. if(g[L][R]!=0 && !used[R])
  21. {
  22. //找增广路,反向
  23. used[R]=true;
  24. if(linker[R] == -1 || dfs(linker[R]))
  25. {
  26. linker[R]=L;
  27. return 1;
  28. }
  29. }
  30. }
  31. return 0;
  32. }
  33. int hungary()
  34. {
  35. int res = 0 ;
  36. int L;
  37. memset(linker,-1,sizeof(linker));
  38. for( L = 1; L <= LN; L++)
  39. {
  40. memset(used,0,sizeof(used));
  41. if(dfs(L) != 0)
  42. res++;
  43. }
  44. return res;
  45. }
  46. void init()
  47. {
  48. memset(a,0,sizeof(a));
  49. memset(vis,0,sizeof(vis));
  50. memset(g,0,sizeof(g));
  51. }
  52. int main()
  53. {
  54. int n, m;
  55. int L, R;
  56. int k;
  57. while(~scanf("%d%d",&n,&m))
  58. {
  59. if(n==0 && m==0)
  60. break;
  61. init();
  62. scanf("%d",&k);
  63. int x, y;
  64. int cont = 1;
  65. for(int i = 1; i <= k; i++)
  66. {
  67. scanf("%d%d",&x,&y);
  68. vis[x][y] = 1;//池塘
  69. }
  70. for(int i = 1; i <= n; i++)
  71. {
  72. for(int j = 1; j <= m; j++)
  73. {
  74. if(!vis[i][j])
  75. {
  76. a[i][j] = cont++;
  77. }
  78. }
  79. }
  80. for(int i = 1; i <= n; i++)
  81. {
  82. for(int j = 1; j <= m; j++)
  83. {
  84. if(!vis[i][j])
  85. {
  86. for(int h = 0; h < 4; h++)
  87. {
  88. int tx = i+dirx[h];
  89. int ty = j+diry[h];
  90. if(tx>=1&&tx<=n && ty>=1&&ty<=m && !vis[i][j])
  91. {
  92. g[a[i][j]][a[tx][ty]] = 1;
  93. g[a[tx][ty]][a[i][j]] = 1;
  94. }
  95. }
  96. }
  97. }
  98. }
  99. LN = cont;
  100. RN = cont;
  101. int ans = hungary();
  102. printf("%d\n",ans/2);
  103. }
  104. return 0 ;
  105. }

ZOJ 1516 Uncle Tom&#39;s Inherited Land(二分匹配 最大匹配 匈牙利啊)的更多相关文章

  1. HDOJ 1507 Uncle Tom&#39;s Inherited Land*

    直接对每一个格子进行dfs结果除以2能够得到答案可是有大量反复的结果,不好输出答案. 能够仅仅对横纵坐标相加是奇数的格子dfs.... Uncle Tom's Inherited Land* Time ...

  2. hdu1507——Uncle Tom&#39;s Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. ZOJ 1516 Uncle Tom's Inherited Land

    题目大意: 除去那些作为荷塘的土地块,将剩余的土地希望每次将两块相邻的地一起卖出,最多能卖出多少种这样的由相邻土地 合成的长方形土地块 很明显的二分图问题,但是要考虑如何建模 一个长方形土地总是由相邻 ...

  5. hdu1507 Uncle Tom's Inherited Land* 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507 将i+j为奇数的构成x集合中 将i+j为偶数的构成y集合中 然后就是构建二部图 关键就是构图 然 ...

  6. HDU 1507 Uncle Tom's Inherited Land*(二分图匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. ZOJ1516 Uncle Tom's Inherited Land(二分图最大匹配)

    一个经典的构图:对格子进行黑白染色,黑白的点分别作XY部的点. 这一题的边就是可以出售的单位面积2的土地,边的端点就是这个土地占用的X部和Y部的两个点. 这样就建好二分图,要求最多土地的答案显然是这个 ...

  8. HDU1507 Uncle Tom's Inherited Land* 二分图匹配 匈牙利算法 黑白染色

    原文链接http://www.cnblogs.com/zhouzhendong/p/8254062.html 题目传送门 - HDU1507 题意概括 有一个n*m的棋盘,有些点是废的. 现在让你用1 ...

  9. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

随机推荐

  1. 学习 WebService 第四步:利用WSDL(URL)生成WebService客户端<初级>

    我用的是最简单的方法,利用jdk的命令wsimport -keep -p 包路径 -d 代码存放位置 WSDL网址 蓝色是命令,粉色是存放位置,橘色是URL C:\Program Files\IBM\ ...

  2. jquery中object对象循环遍历的方法

    一个朋友问对象如何转为数组,当我问他为啥要转得时候,他告诉我,数组可以用js循环遍历,而对象则不可以.其实呢,对象同样可以循环遍历的啊.不用转换也可以循环!说明你对js或者jquery的某些操作不是很 ...

  3. 挑战程序设计2 KD树

    Range Query - Range Search (kD Tree) Time Limit : 1 sec, Memory Limit : 262144 KB Japanese version i ...

  4. 【BZOJ1101】Zap(莫比乌斯反演)

    题意:多组询问,对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d. T,a,b,d,x,y<=50000 思路:下底函数分块+积性函数 ...

  5. 标准C程序设计七---46

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  6. Python日志(logging)模块使用方法简介

    A logger is configured to have a log level. This log level describes the severity of the messages th ...

  7. tomcat 项目迁移到jboss5.1

    1.拷贝tomcat\bin目录下两个jar到项目lib 目的:解决jboss java.lang.NoClassDefFoundError: org/apache/juli/logging/LogF ...

  8. Oracle 12c JDBC方式连接PDB数据库

    1.配置监听 这里假定CDB数据库名为ORCL,PDB在CDB下面名称为PDBORCLlistener.ora添加(#后面为注释,不要添加进去) SID_LIST_LISTENER = (SID_LI ...

  9. [Bzoj5359][Lydsy1805月赛]寻宝游戏(dp)

    5359: [Lydsy1805月赛]寻宝游戏 Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: 71  Solved: 19[Submit][Status ...

  10. Endless Pallet(min-max容斥)

    地址:传送门 分析: 设$x_i$表示第i个点被染成黑色的时间,所求即为$E(max \left \{x_i  \right \})$ 因为$E(X)=\sum_{k=1}^{\infty}i \ti ...