Thanks to a certain "green" resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped up by enterprising oil barons. One such oil baron has a special plane that can skim the surface of the water collecting oil on the water's surface. However, each scoop covers a 10m by 20m rectangle (going either east/west or north/south). It also requires that the rectangle be completely covered in oil, otherwise the product is contaminated by pure ocean water and thus unprofitable! Given a map of an oil slick, the oil baron would like you to compute the maximum number of scoops that may be extracted. The map is an NxN grid where each cell represents a 10m square of water, and each cell is marked as either being covered in oil or pure water.

InputThe input starts with an integer K (1 <= K <= 100) indicating the number of cases. Each case starts with an integer N (1 <= N <= 600) indicating the size of the square grid. Each of the following N lines contains N characters that represent the cells of a row in the grid. A character of '#' represents an oily cell, and a character of '.' represents a pure water cell.OutputFor each case, one line should be produced, formatted exactly as follows: "Case X: M" where X is the case number (starting from 1) and M is the maximum number of scoops of oil that may be extracted.Sample Input

  1. 1
  2. 6
  3. ......
  4. .##...
  5. .##...
  6. ....#.
  7. ....##
  8. ......

Sample Output

  1. Case 1: 3
    题意:给一张图,问最大的连续两个格子数目有多少
    题解:建图太麻烦,实在没想到,看网上思路才a的,把整个图分成i+j%2是否=1两个;然后匹配匈牙利算法就行了
    坑点:刚开始以为由于是从上到下,从左到右遍历的,不用算i-1j-1的情况,才发现这样会少算几种情况。
  1. #include<map>
  2. #include<set>
  3. #include<cmath>
  4. #include<queue>
  5. #include<stack>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<cstdlib>
  9. #include<cstring>
  10. #include<iostream>
  11. #include<algorithm>
  12. #define pi acos(-1)
  13. #define ll long long
  14. #define mod 1000000007
  15.  
  16. using namespace std;
  17.  
  18. const int N=+,maxn=+,inf=0x3f3f3f3f;
  19.  
  20. int n,color[N],col,row;
  21. int u[N][N];
  22. char ma[N][N];
  23. bool used[N],ok[N][N];
  24.  
  25. bool match(int x)
  26. {
  27. for(int i=;i<=row;i++)
  28. {
  29. if(!used[i]&&ok[x][i])
  30. {
  31. used[i]=;
  32. if(color[i]==||match(color[i]))
  33. {
  34. color[i]=x;
  35. return ;
  36. }
  37. }
  38. }
  39. return ;
  40. }
  41. int solve()
  42. {
  43. int ans=;
  44. memset(color,,sizeof color);
  45. for(int i=;i<=col;i++)
  46. {
  47. memset(used,,sizeof used);
  48. ans+=match(i);
  49. }
  50. return ans;
  51. }
  52. int main()
  53. {
  54. ios::sync_with_stdio(false);
  55. cin.tie();
  56. int t;
  57. cin>>t;
  58. for(int k=;k<=t;k++)
  59. {
  60. cin>>n;
  61. for(int i=;i<=n;i++)
  62. for(int j=;j<=n;j++)
  63. cin>>ma[i][j];
  64. col=row=;
  65. memset(u,,sizeof u);
  66. memset(ok,,sizeof ok);
  67. for(int i=;i<=n;i++)
  68. for(int j=;j<=n;j++)
  69. {
  70. if(ma[i][j]=='#')
  71. {
  72. if((i+j)%==)u[i][j]=++col;
  73. if((i+j)%==)u[i][j]=++row;
  74. }
  75. }
  76. for(int i=;i<=n;i++)
  77. for(int j=;j<=n;j++)
  78. {
  79. if((i+j)%==&&ma[i][j]=='#')
  80. {
  81. if(i+<=n&&ma[i+][j]=='#')ok[u[i][j]][u[i+][j]]=;
  82. if(j+<=n&&ma[i][j+]=='#')ok[u[i][j]][u[i][j+]]=;
  83. if(i->=&&ma[i-][j]=='#')ok[u[i][j]][u[i-][j]]=;
  84. if(j->=&&ma[i][j-]=='#')ok[u[i][j]][u[i][j-]]=;
  85. }
  86. if((i+j)%==&&ma[i][j]=='#')
  87. {
  88. if(i+<=n&&ma[i+][j]=='#')ok[u[i+][j]][u[i][j]]=;
  89. if(j+<=n&&ma[i][j+]=='#')ok[u[i][j+]][u[i][j]]=;
  90. if(i->=&&ma[i-][j]=='#')ok[u[i-][j]][u[i][j]]=;
  91. if(j->=&&ma[i][j-]=='#')ok[u[i][j-]][u[i][j]]=;
  92. }
  93. }
  94. /* for(int i=1;i<=n;i++)
  95. {
  96. for(int j=1;j<=n;j++)
  97. cout<<u[i][j];
  98. cout<<endl;
  99. }
  100. for(int i=1;i<=col;i++)
  101. {
  102. for(int j=1;j<=row;j++)
  103. cout<<ok[i][j];
  104. cout<<endl;
  105. }*/
  106. cout<<"Case "<<k<<": "<<solve()<<endl;
  107. }
  108. return ;
  109. }

hdu4185二分图匹配的更多相关文章

  1. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  2. POJ 1274 裸二分图匹配

    题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...

  3. BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2375  Solved: 1005[Submit][Sta ...

  4. HDU1281-棋盘游戏-二分图匹配

    先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边 /*----------------------------------------------------- ...

  5. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

  6. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  7. BZOJ 1059 & 二分图匹配

    题意: 判断一个黑白染色的棋盘能否通过交换行或列使对角线上都是黑色. SOL: 真是有点醉...这种问题要么很神要么很水...第一眼感觉很水但就是不造怎么做...想了10分钟怎么感觉就是判断个数够不够 ...

  8. 【POJ 3020】Antenna Placement(二分图匹配)

    相当于用1*2的板覆盖给定的h*w的格子里的点,求最少的板.可以把格子相邻的分成两个集合,如下图,0为一个集合,1的为一个,也就是(行数+列数)为奇数的是一个集合,为偶数的为另一个集合.1010101 ...

  9. BZOJ-1143&&BZOJ-2718 祭祀river&&毕业旅行 最长反链(Floyed传递闭包+二分图匹配)

    蛋蛋安利的双倍经验题 1143: [CTSC2008]祭祀river Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1901 Solved: 951 ...

随机推荐

  1. Hibernate写配置文件无提示信息解决

    把Hibernate的相关jar包引入工程后,在配置hibernate.cfg.xml时没有提示信息,对于开发人员来说,那么多标签,标签有那么多属性,全部都记住显然是不可能的,遇到这种情况是很头疼的事 ...

  2. CSS后代选择器、子元素选择器、相邻兄弟选择器区别与详解

    派生选择器用的很多,派生选择器具体包括为后代选择器.子元素选择器.相邻兄弟选择器,我们来理解一下他们之间的具体用法与区别. 1.css后代选择器语法:h1 em {color:red;} 表示的是从h ...

  3. 使用gem安装jekyll错误记录

    准备在windows7上安装Jekyll, 安装好了Ruby和RubyDevKit之后,准备使用: $ gem install jekyll 安装jekyll,但是返回错误: ERROR: While ...

  4. jquery data属性的使用

    var func=function(){console.log("test")};$("div").data("test",func);$( ...

  5. js精确计算

    官方文档:http://mikemcl.github.io/big.js/ 使用方法: x = new Big(0.1); y = x.plus(0.2); // '0.3' var a=Big(0. ...

  6. ROS多机通信计算机网络配置

    以实现master和nico的互联共享信息为例 1 查看IP地址 $ifconfig 查看ip地址 可以看到 master的IP为192.168.1.10 nico的IP为192.168.1.103 ...

  7. 老李教你性能测试监控工具nmon

    老李教你性能测试监控工具nmon   loadrunner的某些性能监控器不够强大,这就需要我们利用更好的工具进行监控,在项目中我们会用nmon工具作为辅助性能监控的工具,帮助我们进行性能分析,pop ...

  8. Hibernate基础学习(三)—Session

    一.概述      Session接口是Hibernate向应用程序提供的操纵数据库最主要的接口,它提供了基本的保存.更新.删除和加载Java对象的方法.      Session具有一个缓存,位于缓 ...

  9. Entity Framework快速入门--IQueryable与IEnumberable的区别

    IEnumerable接口 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代.也就是说:实现了此接口的object,就可以直接使用foreach遍历此object: IQueryable 接口 ...

  10. Centos7部署Zabbix

    转载于http://www.cnblogs.com/xqzt/p/5124894.html,更正了部分错误,并增加了个别问题处理办法. 一.Zabbix简介 zabbix是一个基于WEB界面的提供分布 ...