Oil Skimming

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

题目链接:acm.hdu.edu.cn/showproblem.php?pid=4185

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
 
题解:
每个‘#’看出一个点,然后对挨着的‘#’进行二分图的最大匹配,双向图最后结果除以2
 
代码如下
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define mem(x) memset(x,0,sizeof(x))
using namespace std; const int N = ;
int check[N],match[N],map[N][N],link[N][N];
int Case,n,tot,ans,dfn,t=; inline void update(int x,int y){
if(map[x+][y]) link[map[x][y]][map[x+][y]]=;
if(map[x-][y]) link[map[x][y]][map[x-][y]]=;
if(map[x][y+]) link[map[x][y]][map[x][y+]]=;
if(map[x][y-]) link[map[x][y]][map[x][y-]]=;
} inline int dfs(int x){
for(int i=;i<=tot;i++){
if(link[x][i] && check[i]!=dfn){
check[i]=dfn;
if(match[i]== || dfs(match[i])){
match[i]=x;
return ;
}
}
}
return ;
}
int main(){
scanf("%d",&Case);
while(Case--){
t++;
scanf("%d",&n);
mem(map);mem(match);mem(link);tot=;ans=;dfn=;mem(check);
for(int i=;i<=n;i++){
char s[N];
scanf("%s",s+);
for(int j=;j<=n;j++){
if(s[j]=='#') map[i][j]=++tot;
}
}
for(int i=;i<=n;i++) for(int j=;j<=n;j++) if(map[i][j]) update(i,j);
for(int i=;i<=tot;i++){
dfn++;
if(dfs(i)) ans++;
}
printf("Case %d: %d\n",t,ans/);
}
return ;
}

HDU4185:Oil Skimming(二分图最大匹配)的更多相关文章

  1. HDU4185 Oil Skimming 二分图匹配 匈牙利算法

    原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...

  2. HDU4185 Oil Skimming —— 最大匹配

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

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

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

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

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

  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 Problem Description Thanks to a certain "green" resources company, there is a ...

  7. HDU 4185 Oil Skimming 【最大匹配】

    <题目链接> 题目大意: 给你一张图,图中有 '*' , '.' 两点,现在每次覆盖相邻的两个 '#' ,问最多能够覆盖几次. 解题分析: 无向图二分匹配的模板题,每个'#'点与周围四个方 ...

  8. hdu4185 Oil Skimming(偶匹配)

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

  9. HDU4185(KB10-G 二分图最大匹配)

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

随机推荐

  1. SVM中的间隔最大化

    参考链接: 1.https://blog.csdn.net/TaiJi1985/article/details/75087742 2.李航<统计学习方法>7.1节 线性可分支持向量机与硬间 ...

  2. HyperLedger Fabric 1.4 超级账本起源(5.1)

    至比特币开源以来,无数技术人员对其进行研究,并且对该系统经过了无数次改进,超级账本项目(Hyperledger)最初也是用来改善比特币的底层技术,最终由Linux基金会组织发展起来.       开放 ...

  3. 【转】Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法

    Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法 [原文链接] 这篇文章完美的解决了我几个月没结论的bug... 感谢热爱分享的技术达人~ 我是怎么走进这个大坑的 ...

  4. python2.7入门---字符串

        这次咱们就来看一下python的字符串类型.首先我们要知道,字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串.创建字符串很简单,只要为变量分配一个值 ...

  5. Druid时序数据库常见问题及处理方式

    最近将Druid-0.10.0升级到Druid-0.12.1的过程中遇到一些问题,为了后期方便分析问题和及时解决问题,特此写这篇文章将工作中遇到的Druid问题及解决办法记录下来,以供其他人借鉴,其中 ...

  6. Android开发——Android系统启动以及APK安装、启动过程

    0. 前言   从Android手机打开开关,到我们可以使用其中的app时,这个启动过程到底是怎么样的? 1.  系统上电 当给Android系统上电,在电源接通的瞬间,CPU内的寄存器和各引脚均会被 ...

  7. golang 小知识点记录

    获取url中的参数及输出到页面的几种方式 func SayHello(w http.ResponseWriter, req *http.Request) { req.Method //获取url的方法 ...

  8. jmeter多用户登录跨线程组操作传值

    项目需求: 需要登录两个用户A.B,用户A操作完后会通知B,然后B再操作,B操作完结束或者再通知A. 实现思路: 1. 设置两个线程组Ⅰ.Ⅱ,组Ⅰ添加cookie管理器,里面添加用户A的操作:组Ⅱ添加 ...

  9. ABP框架设置默认语言

    在Global.asax文件中设置 private readonly IAbpWebLocalizationConfiguration _webLocalizationConfiguration; p ...

  10. asm和file system之间数据文件的转换

    How to move a datafile from a file system to ASMMoving a datafile from the file system can be achive ...