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

二分匹配,计算出里边有多少个‘#’,将这些编号,之后查找,如果他的周围是“#”,就将这两个连一条边。之后跑一边匈牙利;点数就是‘#’数目;

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
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
char mp[650][650];
int g[650][650];
int vis[1000];
int dis[1000];
int dp[1000][1000];//新图的地图
int n,t;
int v;//建立新图的边
/* 匈 牙 利 算 法 */
int find(int x)
{
for(int i=0;i<v;i++)
{
if(!vis[i]&&dp[x][i])
{
vis[i]=1;
if(dis[i]==0||find(dis[i]))
{
dis[i]=x;
return 1;
}
}
}
return 0;
}
int maxp()
{
int ans=0;
memset(dis,0,sizeof(dis));
for(int i=0;i<v;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
ans++;
}
return ans;
}
int main()
{
int t,icase=1;
cin>>t;
while(t--)
{
cin>>n;
int cnt=0,ans=0;
memset(mp,0,sizeof(mp));
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
{
scanf("%s",mp[i]);
for(int j=0;j<n;j++)
{
if(mp[i][j]=='#')//
g[i][j]=cnt++;
}
}
v=cnt;//新图的边
for(int i=0;i<n;i++)/*保存新图,即将题给的图转换成点与点之间边的关系*/
{
for(int j=0;j<n;j++)
{
if(mp[i][j]!='#') continue;
if(i>0&&mp[i-1][j]=='#') dp[g[i-1][j]][g[i][j]]=1;
if(i<n-1&&mp[i+1][j]=='#') dp[g[i+1][j]][g[i][j]]=1;
if(j>0&&mp[i][j-1]=='#') dp[g[i][j-1]][g[i][j]]=1;
if(j<n-1&&mp[i][j+1]=='#') dp[g[i][j+1]][g[i][j]]=1;
}
}
ans=maxp();
printf("Case %d: %d\n",icase++,ans/2);
}
}

H - Oil Skimming (挖石油)的更多相关文章

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

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

  2. J - Oil Skimming 二分图的最大匹配

    Description Thanks to a certain "green" resources company, there is a new profitable indus ...

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

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

  4. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  5. Hdu4185 Oil Skimming

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

  6. Oil Skimming HDU - 4185(匹配板题)

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

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

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

  8. HDU4185 Oil Skimming —— 最大匹配

    题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memo ...

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

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

随机推荐

  1. Zero date value prohibited解决方法

    发现错误 在做新需求时,建了新表,但是在测试debug中,控制台报了java.sql.SQLException: Zero date value prohibited错误 数据库用的是Date类型 实 ...

  2. idea生成UML

    原文链接http://zhhll.icu/2020/12/18/idea/%E7%94%9F%E6%88%90UML/ 使用idea直接生成UML类图 然后点击所要生成的类即可生成 由于本身的博客百度 ...

  3. Java实现RS485串口通信

    前言 前段时间赶项目的过程中,遇到一个调用RS485串口通信的需求,赶完项目因为楼主处理私事,没来得及完成文章的更新,现在终于可以整理一下当时的demo,记录下来. 首先说一下大概需求:这个项目是机器 ...

  4. oracle 11.2.0.1.0 升级 11.2.0.4.0 并 patch 到11.2.0.4.7

    升级步骤: (1)    备份数据库 (2)    运行patchset,升级oracle 软件 (3)    准备新的ORACLE_HOME (4)    运行dbua 或者脚本升级实例 (5)   ...

  5. 【剑指 Offer】11.旋转数组的最小数字

    题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的 ...

  6. Docker学习笔记之向服务器部署应用程序

    部署的应用仅仅是简单应用程序,使用的是node管理的web应用,具体我也不是很会,当然也可以配置tomcat服务器.这里主要是学习docker.需要客户机和服务机,其中服务机必须要为Linux操作系统 ...

  7. 【Python】国内pip节点

    pip在国内使用国内节点: http://pypi.douban.com/simple 现在已经无法使用了,新版的python3需要使用https://pypi.douban.com/simple/ ...

  8. C#数组的 Length 和 Count()

    C#数组的 Length 和 Count() C# 数组中 Length 表示数组项的个数,是个属性.而 Count() 也是表示项的个数,是个方法,它的值和 Length 一样.但实际上严格地说, ...

  9. Windows下的python虚拟环境设置

    Windows下的python虚拟环境设置: virtualenv 在python开发中,我们可能会遇到一种情况:就是当前的项目依赖的是某一个版本,但是另一个项目依赖的是另一个版本,这样就会造成依赖冲 ...

  10. GlusterFS数据存储脑裂修复方案最全解析

    本文档介绍了glusterfs中可用于监视复制卷状态的heal info命令以及解决脑裂的方法 一. 概念解析 常见术语 名称 解释 Brick GlusterFS 的基本存储单元,由可信存储池中服务 ...