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

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

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. DHCP.md

    DHCP 主配置文件   从 /usr/share/doc/dhcp 复制 dhcpd.conf.sample 到/etc/dhcp下                                  ...

  2. 【Flutter】可滚动组件之ListView

    前言 它可以沿一个方向线性排布所有子组件,并且它也可以支持基于Sliver的延迟构建模型. 接口描述 ListView({ Key key, // 可滚动widget公共参数 Axis scrollD ...

  3. 一文带你探究Sentinel的独特初始化

    摘要:本系列通过作者对Redis Sentinel源码的理解,详细说明Sentinel的代码实现方式. Redis Sentinel 是Redis提供的高可用模型解决方案.Sentinel可以自动监测 ...

  4. 微信小程序request请求的封装

    目录 1,前言 2,实现思路 3,实现过程 3.1,request的封装 3.2,api的封装 4,实际使用 1,前言 在开发微信小程序的过程中,避免不了和服务端请求数据,微信小程序给我们提供了wx. ...

  5. Python绘制雷达图(俗称六芒星)

    原文链接:https://blog.csdn.net/Just_youHG/article/details/83904618 背景 <Python数据分析与挖掘实战> 案例2–航空公司客户 ...

  6. 【Spring】Spring中的Bean - 4、Bean的生命周期

    Bean的生命周期 简单记录-Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)-Spring中的Bean 了解Spring中Bean的生命周期有何意义? 了解Sp ...

  7. 如何用Python中自带的Pandas和NumPy库进行数据清洗

    一.概况 1.数据清洗到底是在清洗些什么? 通常来说,你所获取到的原始数据不能直接用来分析,因为它们会有各种各样的问题,如包含无效信息,列名不规范.格式不一致,存在重复值,缺失值,异常值等..... ...

  8. Pytorch 中张量的理解

    张量是一棵树 长久以来,张量和其中维度的概念把我搞的晕头转向. 一维的张量是数组,二维的张量是矩阵,这也很有道理. 但是给一个二维张量,让我算出它每一行的和,应该用 sum(dim=0) 还是 sum ...

  9. 部署自动初始化Schema的数据库

    我们使用容器的方式部署数据库组件,特别是企业有大量的项目开发业务的,部署的开发.测试数据库组件较多时.经常会遇到以下问题: 业务需要使用数据库,但部署完数据库后,需要在数据库中执行创建schema的操 ...

  10. Java并发组件二之CyclicBarriar

    使用场景: 多个线程相互等待,直到都满足条件之后,才能执行后续的操作.CyclicBarrier描述的是各个线程之间相互等待的关系. 使用步骤: 正常实例化:CyclicBarrier sCyclic ...