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
6
......
.##...
.##...
....#.
....##
......

Sample Output

Case 1: 3
题意:给一张图,问最大的连续两个格子数目有多少
题解:建图太麻烦,实在没想到,看网上思路才a的,把整个图分成i+j%2是否=1两个;然后匹配匈牙利算法就行了
坑点:刚开始以为由于是从上到下,从左到右遍历的,不用算i-1,j-1的情况,才发现这样会少算几种情况。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; int n,color[N],col,row;
int u[N][N];
char ma[N][N];
bool used[N],ok[N][N]; bool match(int x)
{
for(int i=;i<=row;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(color[i]==||match(color[i]))
{
color[i]=x;
return ;
}
}
}
return ;
}
int solve()
{
int ans=;
memset(color,,sizeof color);
for(int i=;i<=col;i++)
{
memset(used,,sizeof used);
ans+=match(i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int t;
cin>>t;
for(int k=;k<=t;k++)
{
cin>>n;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>ma[i][j];
col=row=;
memset(u,,sizeof u);
memset(ok,,sizeof ok);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
if(ma[i][j]=='#')
{
if((i+j)%==)u[i][j]=++col;
if((i+j)%==)u[i][j]=++row;
}
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
if((i+j)%==&&ma[i][j]=='#')
{
if(i+<=n&&ma[i+][j]=='#')ok[u[i][j]][u[i+][j]]=;
if(j+<=n&&ma[i][j+]=='#')ok[u[i][j]][u[i][j+]]=;
if(i->=&&ma[i-][j]=='#')ok[u[i][j]][u[i-][j]]=;
if(j->=&&ma[i][j-]=='#')ok[u[i][j]][u[i][j-]]=;
}
if((i+j)%==&&ma[i][j]=='#')
{
if(i+<=n&&ma[i+][j]=='#')ok[u[i+][j]][u[i][j]]=;
if(j+<=n&&ma[i][j+]=='#')ok[u[i][j+]][u[i][j]]=;
if(i->=&&ma[i-][j]=='#')ok[u[i-][j]][u[i][j]]=;
if(j->=&&ma[i][j-]=='#')ok[u[i][j-]][u[i][j]]=;
}
}
/* for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<u[i][j];
cout<<endl;
}
for(int i=1;i<=col;i++)
{
for(int j=1;j<=row;j++)
cout<<ok[i][j];
cout<<endl;
}*/
cout<<"Case "<<k<<": "<<solve()<<endl;
}
return ;
}

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. MonkeyRunner之小白如何使用MonkeyRecorder录制回放脚本

    之前摸索了好久.学习Python语言.安装工具.拉拉溜溜也慢慢地一点点进步.每天就疯狂的上网找资料.虽然大牛们写的很详细.但是自己就是笨的不知怎么做.最后找了一篇文章,真的就是万事俱备只欠东风的感觉, ...

  2. Mac系统安装nginx+rtmp模块

    1.安装命令 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) ...

  3. Jmeter添加监控指标

    需要监控的机器上安装Server-Agency(需要java环境支持)把ServerAgent-2.2.1.zip拷到需要监控的机器上,解压Linux启动如下2. Jmeter上添加监控最终有如下指标 ...

  4. 通用数据库帮助类DBHelper(含log日志信息实时记录)

    项目需要,需要一个通用的数据库操作类,增删改查.事务.存储过程.日志记录都要有,于是在已有的帮助类上做了一些改进,并将log4j的.NET版--log4net嵌入其中记录sql的执行环境和状态. 用起 ...

  5. 第六章:3D向量类

    第一节:类接口的设计 1.好的类在设计之前首先要回答下列问题:“这些类将包含哪些数据?”,“这个类将提供什么样的操作?”,“在哪些数据上执行操作?”. 我们已经知道我们要设计的是3D向量类,用来存储x ...

  6. 自己写的一个 java swing 的闹钟

    上一周新入职,把代码down下来之后,领导和我讲了一些大概的业务以及代码流程(领导是技术出身),领导让我自己先看看代码,然后我看了两天,觉得已经完全可以接任务了,但是领导却迟迟没有分配任务给我,虽然他 ...

  7. XML和JSON两种数据交换格式的比较

    在web开发领域,主要的数据交换格式有XML和JSON,对于在 Ajax开发中,是选择XML还是JSON,一直存在着争议,个人还是比较倾向于JSON的.一般都输出Json不输出xml,原因就是因为 x ...

  8. Mesos+Zookeeper+Marathon+Docker分布式集群管理最佳实践

    参考赵班长的unixhot以及马亮blog 笔者QQ:572891887 Linux架构交流群:471443208 1.1Mesos简介 Mesos是Apache下的开源分布式资源管理框架,它被称为分 ...

  9. 【Spring】BeanFactory解析bean详解

    在该文中来讲讲Spring框架中BeanFactory解析bean的过程,该文之前在小编原文中有发表过,要看原文的可以直接点击原文查看,先来看一个在Spring中一个基本的bean定义与使用. pac ...

  10. 手机自动化测试:appium源码分析之bootstrap九

    手机自动化测试:appium源码分析之bootstrap九   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣, ...