Oil Skimming

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

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
 
Recommend
lcy
 

就是一个板题。。。

相邻的两个#建边。。。。然后求最大匹配就好了

用匈牙利就够了  我用的hc

#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
int dx[maxn], dy[maxn], cx[maxn], cy[maxn], used[maxn];
int nx, ny, dis, n;
char str[][];
int gra[][];
vector<int> G[];
int dir[][] = {{,},{-,},{,},{,-}};
int bfs()
{
queue<int> Q;
dis = INF;
mem(dx, -);
mem(dy, -);
for(int i=; i<=nx; i++)
{
if(cx[i] == -)
{
Q.push(i);
dx[i] = ;
}
}
while(!Q.empty())
{
int u = Q.front(); Q.pop();
if(dx[u] > dis) break;
for(int v=; v<G[u].size(); v++)
{
int i=G[u][v];
if(dy[i] == -)
{
dy[i] = dx[u] + ;
if(cy[i] == -) dis = dy[i];
else
{
dx[cy[i]] = dy[i] + ;
Q.push(cy[i]);
}
}
}
}
return dis != INF;
} int dfs(int u)
{
for(int v=; v<G[u].size(); v++)
{
int i = G[u][v];
if(!used[i] && dy[i] == dx[u] + )
{
used[i] = ;
if(cy[i] != - && dis == dy[i]) continue;
if(cy[i] == - || dfs(cy[i]))
{
cy[i] = u;
cx[u] = i;
return ;
}
}
}
return ;
} int hk()
{
int res = ;
mem(cx, -);
mem(cy, -);
while(bfs())
{
mem(used, );
for(int i=; i<=nx; i++)
if(cx[i] == - && dfs(i))
res++;
}
return res;
} int main()
{
int T, kase = ;
cin>> T;
while(T--)
{
mem(gra, );
int ans = ;
for(int i=; i<maxn; i++) G[i].clear();
cin>> n;
for(int i=; i<n; i++)
{
cin>> str[i];
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
gra[i][j] = ++ans; } }
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
for(int k=; k<; k++)
{
int nx = i + dir[k][];
int ny = j + dir[k][];
if(str[nx][ny] == '#' && nx >= && ny >= && nx < n && ny < n)
G[gra[i][j]].push_back(gra[nx][ny]), G[gra[nx][ny]].push_back(gra[i][j]);
}
}
}
nx = ny = ans;
printf("Case %d: %d\n",++kase, hk()/);
} return ;
}

Oil Skimming HDU - 4185(匹配板题)的更多相关文章

  1. (匹配)Oil Skimming -- hdu --4185

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4185 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  2. G - Oil Skimming - hdu 4185(二分图匹配)

    题意:在大海里有一些石油 ‘#’表示石油, ‘.’表示水,有个人有一个工具可以回收这些石油,不过只能回收1*2大小的石油块,里面不能含有海水,要不就没办法使用了,求出来最多能回收多少块石油 分析:先把 ...

  3. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

  4. hdu4185 Oil Skimming(偶匹配)

    <span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...

  5. HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】

    Oil Skimming Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  6. HDU4185:Oil Skimming(二分图最大匹配)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. H - Oil Skimming (挖石油)

    题意大概是,海上漂浮着一些符号为#的石油,你要去搜集他们,但是你的勺子呢能且只能挖到两个单元的石油.问你最多能挖多少勺.注意 不能挖到纯净的海水,不然石油会被纯净的海水稀释的. 二分匹配,计算出里边有 ...

  8. Hdu4185 Oil Skimming

    Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...

  9. 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)

    如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...

随机推荐

  1. P2731 骑马修栅栏 Riding the Fences

    题目描述 John是一个与其他农民一样懒的人.他讨厌骑马,因此从来不两次经过一个栅栏.你必须编一个程序,读入栅栏网络的描述,并计算出一条修栅栏的路径,使每个栅栏都恰好被经过一次.John能从任何一个顶 ...

  2. 串口通信DMA中断

    这是以前学32的时候写的,那时候学了32之后感觉32真是太强大了,比51强的没影.关于dma网上有许多的资料,亲们搜搜,这里只贴代码了,其实我也想详详细细地叙述一番,但是自己本身打字就慢,还有好多事情 ...

  3. TTL,COMS,USB,232,422,485电平之详细介绍及使用

    如有错误敬请指导! 今天来详细介绍一下TTL,COMS,USB,232,422,485电平,以及之间的转换问题. 有些地方的引脚图可能不是规范的,具体引脚以自己的模块资料为主,这篇文章着重介绍使用.. ...

  4. 关于MSCOCO_text数据集的探索

    最近需要做图片中文本识别的项目,然后为了快速验证模型,所以找到了mscoco-text数据集,网站1上是这么说的: 官网是这么说的: 然而,我下下来之后: 1 - 先导入: 2 - 其中key为'im ...

  5. 2.3《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——重命名,复制,删除

    最常用的文件操作除了将文件列出来外,就应该是重命名,复制,删除了.正如将文件列出来一样,大多数现代操作系统为这些任务提供了用户图形界面,但是在许多场景中,用命令行还是会更方便. 使用mv命令重命名一个 ...

  6. MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途(转)

    本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TEST三个数据库的用途. 第一个数据库INFORMATION_SCHEMA:提供了访问数据库元数据的方式 ...

  7. 20155206《网络对抗》Web安全基础实践

    20155206<网络对抗>Web安全基础实践 实验后问题回答 (1)SQL注入攻击原理,如何防御 攻击原理:SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查 ...

  8. Luogu T24242 购物券Ⅰ(数据已加强)

    这是一道比赛时的题目,但由于我没报名,所以浪费了一个大好的切水题的机会. 是经典的meet in middle(折半搜索)的模板题,但是之前一直没找到这种题目,今天终于看到了. 由于m的范围极大,因此 ...

  9. EZ 2018 02 28 NOIP2018 模拟赛(二)

    我TM的终于改完了(其实都是SB题) 题目链接:http://211.140.156.254:2333/contest/53 T1送分,T2前40%送分,还有骗分机制在里面,T3暴力50 所以200应 ...

  10. tkinter 弹出窗口 传值回到 主窗口

    有些时候,我们需要使用弹出窗口,对程序的运行参数进行设置.有两种选择 一.标准窗口 如果只对一个参数进行设置(或者说从弹出窗口取回一个值),那么可以使用simpledialog,导入方法: from ...