Oil Skimming

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1487    Accepted Submission(s): 612

Problem Description
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.
 
Input
The
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.
 
Output
For
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
 
Source
 
 
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ;
const int INF = ;
bool vis[maxn];
int link[maxn];
int G[maxn][maxn];
int x_cnt;
int y_cnt;
int temp[maxn][maxn];
char str[maxn][maxn];
bool find(int u)
{
for(int i = ; i <= y_cnt; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = true;
if(link[i] == - || find(link[i]))
{ link[i] = u;
return true;
}
}
}
return false;
}
int solve()
{
int num = ;
memset(link, -, sizeof(link));
for(int i = ; i <= x_cnt; i++)
{
memset(vis, false, sizeof(vis));
if(find(i))
num++;
}
return num;
}
int main()
{
int t,cnt=;
scanf("%d",&t);
while(t--){
cnt++;
int n;
scanf("%d",&n);
int tmp=;
memset(temp,,sizeof(temp));
memset(G,,sizeof(G));
memset(str,,sizeof(str));
for(int i=;i<n;i++)
{
scanf("%s",&str[i]);
for(int j=;j<n;j++)
if(str[i][j]=='#')
temp[i][j]=++tmp;
}
x_cnt=tmp, y_cnt=tmp;
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if(str[i][j]!='#') continue;
if(i>&&str[i-][j]=='#') G[temp[i][j]][temp[i-][j]]=;
if(i<n-&&str[i+][j]=='#') G[temp[i][j]][temp[i+][j]]=;
if(j>&&str[i][j-]=='#') G[temp[i][j]][temp[i][j-]]=;
if(j<n-&&str[i][j+]=='#') G[temp[i][j]][temp[i][j+]]=;
} printf("Case %d: %d\n",cnt,solve()/);
}
return ;
}

hdu 4185 二分图最大匹配的更多相关文章

  1. hdu 1281 二分图最大匹配

    对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1   Y1 X2   Y2 X3   Y3 ..... Xn   Yn ...

  2. HDU - 2444 二分图最大匹配 之 判断二分图+匈牙利算法

    题意:第一行给出数字n个学生,m条关系,关系表示a与b认识,判断给定数据是否可以构成二分图,如果可以,要两个互相认识的人住一个房间,问最大匹配数(也就是房间需要的最小数量) 思路:要看是否可以构成二分 ...

  3. hdu 4185 二分图匹配

    题意用1*2的木板覆盖矩阵中的‘#’,(木板要覆盖的只能是‘#’),问最多能用几个木板覆盖 将#抽象为二分图的点,一个木板就是一个匹配,注意最后结果要除以2 Sample Input 1 6 .... ...

  4. hdu 4619 二分图最大匹配 ——最大独立集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...

  5. HDU 3279 二分图最大匹配

    DES: 就是说对每个人都给你一个区间.但一个人只匹配一个数.问你满足匹配的人的序号字典序最大时的最大匹配是什么. 前几天刚做的UVALive 6322...当然是不一样的...那个要求的最大匹配的个 ...

  6. hdu 3729(二分图最大匹配)

    I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. HDU:过山车(二分图最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意:有m个男,n个女,和 k 条边,求有多少对男女可以搭配. 思路:裸的二分图最大匹配,匈牙利算法. 枚 ...

  8. [HDU] 2063 过山车(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio> ...

  9. HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配)

    HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...

随机推荐

  1. 【CF1000C】Covered Points Count(离散化+差分)

    点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...

  2. 设置和重置ssh key

    查看本地是否有已经生成好的ssh key $ cat ~/.ssh/id_rsa.pub 若有,先删除: $ cd ~ $ rm -rf .ssh 重新生成ssh key ssh-keygen -t ...

  3. Problem K: 搜索基础之棋盘问题

    Problem K: 搜索基础之棋盘问题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 92  Solved: 53[Submit][Status][W ...

  4. javaweb基础(30)_EL函数库

    一.EL函数库介绍 由于在JSP页面中显示数据时,经常需要对显示的字符串进行处理,SUN公司针对于一些常见处理定义了一套EL函数库供开发者使用. 这些EL函数在JSTL开发包中进行描述,因此在JSP页 ...

  5. Oracle 配置文件目录

    Oracle 配置文件目录 ① 在oracle安装目录下,找D:\oracle\product\10.2.0\client_1\NETWORK\ADMIN中的tnsnames.ora文件,找到之后,配 ...

  6. 谭浩强 c++程序设计第一章课后习题 第7题

    #include <iostream> using namespace std; int main() { int a,b,c; int f(int x,int y,int z);//这是 ...

  7. eclipse中使用git上传项目

    eclipse中使用git上传项目 先需要上传到本地仓库 先找到此选项打钩 再如下 再添加的属性则可以自动填充邮箱和密码 之后 右键选择import 点击找到git 选中 下一步  如果没有找到git ...

  8. Class:向传统类模式转变的构造函数

    前言 JS基于原型的'类',一直被转行前端的码僚们大呼惊奇,但接近传统模式使用class关键字定义的出现,却使得一些前端同行深感遗憾而纷纷留言:"还我独特的JS"."净搞 ...

  9. Federated引擎

    Federated就像他的名字所说“联盟”,其作用就是把两个不同区域的数据库联系起来,以至可以访问在远程数据库的表中的数据,而不是本地的表. 1.进入mysql命令行,查看是否已安装Federated ...

  10. python3.7 json模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 json模块 ''' 要在不同的编程语言之间传递对象,就必须把对 ...