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. php实现远程网络文件下载到服务器指定目录(方法二)

    <?php // maximum execution time in seconds set_time_limit (24 * 60 * 60); //if (!isset($_POST['su ...

  2. CAN总线学习系列之三——CAN控制器的选择

    CAN总线学习系列之三——CAN控制器的选择 在进行CAN总线开发前,首先要选择好CAN总线控制器.下面就比较一些控制器的特点. 一些主要的CAN总线器件产品 制造商 产品型号 器件功能及特点 Int ...

  3. python中安装Tensorflow

    执行命令:pip install --upgrade tensorflow 即可.

  4. 20155203 杜可欣《网络对抗技术》Exp1 PC平台逆向破解

    1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同时包含另一个代码片段,ge ...

  5. 20155237 《JAVA程序设计》实验二(JAVA面向对象程序设计)实验报告

    20155237 <JAVA程序设计>实验二(JAVA面向对象程序设计)实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S ...

  6. 20155305《网络对抗》Web基础

    20155305<网络对抗>Web基础 实验过程 Web前端:HTML 使用netstat -aptn查看80端口是否被占用(上次实验设置为Apache使用80端口),如果被占用了就kil ...

  7. 20155327 实验四 Android程序设计

    20155327 实验四 Android程序设计 任务一: 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号 步骤: 将布局文件activity_ma ...

  8. 20155339平措卓玛 Exp2 后门原理与实践

    20155339平措卓玛Exp2 后门原理与实践 基础问题 (1)例举你能想到的一个后门进入到你系统中的可能方式? 答:下载并安装某个程序,这个程序可以正常的并且完整的为我们提供服务,但是在开发改程序 ...

  9. mfc Unicode转 ASNI ,WCHAR 转 CHAR

    知识点: 宽字符转多字节字符 多字节字符转宽字符 什么是ANSI,什么又是UNICODE呢?其实这是两种不同的编码方式标准,ANSI中的字符采用8bit,而UNICODE中的字符采用16bit 在VC ...

  10. EJB开发第二期---开发具有本地接口的无状态Bean

    一.EJB中的bean 1.1 EJB中bean分类 会话bean(session bean) 负责与客户端交互,是编写业务逻辑的地方,在会话bean中可以通过jdbc直接操作数据库,但大多数情况下都 ...