HDU4185:Oil Skimming(二分图最大匹配)
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:
#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(二分图最大匹配)的更多相关文章
- HDU4185 Oil Skimming 二分图匹配 匈牙利算法
原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...
- HDU4185 Oil Skimming —— 最大匹配
题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)
如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...
- J - Oil Skimming 二分图的最大匹配
Description Thanks to a certain "green" resources company, there is a new profitable indus ...
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Hdu4185 Oil Skimming
Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...
- HDU 4185 Oil Skimming 【最大匹配】
<题目链接> 题目大意: 给你一张图,图中有 '*' , '.' 两点,现在每次覆盖相邻的两个 '#' ,问最多能够覆盖几次. 解题分析: 无向图二分匹配的模板题,每个'#'点与周围四个方 ...
- hdu4185 Oil Skimming(偶匹配)
<span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...
- HDU4185(KB10-G 二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- 2.从print到自省
print是一个函数 为什么print是一个函数呢?可以在交互式解释器下 输入: >>> type(print) 输出: <class 'builtin_function_ ...
- 爬虫之requests模块基础
一.request模块介绍 1. 什么是request模块 - python中原生的基于网络请求的模块,模拟浏览器发起请求. 2. 为什么使用request模块 - urllib需要手动处理url编码 ...
- R语言学习笔记(二): 类与泛型函数
类 大多数R对象都是基于S3类(来源于第三代S语言),例如直方图函数hist()输出是一个包含多个组件的列表,它还有一个属性(attribute),用来指定列表的类,即histogram类. 泛型函数 ...
- js数组长度
js数组长度,一般使用length 属性即可获取,但这个数组是个对象则只能使用以下方式 var t=typeof o; var length=0; if(t=='string'){ length=o. ...
- ThinkPhP html原样入库
开始正式搞php,在配置好PHP环境之后,从学习thinkphp框架开始php之旅. 在实际项目中需要将一个网页的html保存到数据库中,但不能被转义.由于thinkphp的数据库操作为通过他们自己O ...
- win10激活方法-专业版
该教程操作思路,Win10家庭版升为专业版,然后激活版本 首先,进入设置→关于看到如下页面: 接着,进入实操阶段: 第一步 在激活版面输入密匙 ( 把家庭版升级为专业版 ) DR9VN-GF3 ...
- C++STL——概述
一.相关介绍 STL 标准模板库 在编写代码的过程中有一些程序经常会被用到,而且需求特别稳定,所以C++中把这些常用的模板做了统一的规范,慢慢的就形成了STL 提供三种类型的组件: 容器.迭代器和算法 ...
- Linux C++线程池实例
想做一个多线程服务器测试程序,因此参考了github的一些实例,然后自己动手写了类似的代码来加深理解. 目前了解的线程池实现有2种思路: 第一种: 主进程创建一定数量的线程,并将其全部挂起,此时线程状 ...
- lintcode-115-不同的路径 II
115-不同的路径 II "不同的路径" 的跟进问题: 现在考虑网格中有障碍物,那样将会有多少条不同的路径? 网格中的障碍和空位置分别用 1 和 0 来表示. 注意事项 m 和 n ...
- 怎么获取textarea中选中文字
textarea设置select="saveSelectionText()" //保存选中内容 saveSelectionText: function () { var focus ...