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

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

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. Head First 设计模式 —— 13. 代理 (Proxy) 模式

    思考题 如何设计一个支持远程方法调用的系统?你要怎样才能让开发人员不用写太多代码?让远程调用看起来像本地调用一样,毫无瑕疵? P435 已经接触过 RPC 了,所以就很容易知道具体流程:客户端调用目标 ...

  2. Linux 中软链接和硬链接的使用

    Linux 链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link). 硬链接和软链接 硬链接 --- ln 要链接的文件 新硬链接名 软连接 --- l ...

  3. 2021升级版微服务教程7-OpenFeign实战开发和参数调优

    2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 教程全目录「含视频」:https://gitee.c ...

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

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

  5. 阿里云OSS对象存储服务(二)

    一.使用SDK 在OSS的概览页右下角找到"Bucket管理",点击"OSS学习路径" 点击"Java SDK"进入SDK开发文档 二.创建 ...

  6. 动态改变div标签中的内容

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 【Android初级】使用TypeFace设置TextView的文字字体(附源码)

    在Android里面设置一个TextView的文字颜色和文字大小,都很简单,也是一个常用的基本功能.但很少有设置文字字体的,今天要分享的是通过TypeFace去设置TextView的文字字体,布局里面 ...

  8. 聊一聊:Service层你觉得有用吗?

    前段日子在社群(点击加入)里看到有人讨论关于Service层接口的问题,DD也经常碰到周围的新人有问过一些类似的问题:一定要写个Service层的接口吗?Service层的接口到底用做什么用的呢?好像 ...

  9. windows和linux修改ipv6和ipv4的优先级

    如果一台机器系统配置ipv6地址和ipv4地址共存,访问两种网站都可以 但有个很尴尬的问题,因为操作系统默认是V6优先于V4,所以比如一个地址同时有A和AAAA记录的话,那么系统会自动选择V6协议通信 ...

  10. Linux kernel 同步机制

    Linux kernel同步机制(上篇) https://mp.weixin.qq.com/s/mosYi_W-Rp1-HgdtxUqSEgLinux kernel 同步机制(下篇) https:// ...