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 ...
随机推荐
- Java学习笔记十四:如何定义Java中的类以及使用对象的属性
如何定义Java中的类以及使用对象的属性 一:类的重要性: 所有Java程序都以类class为组织单元: 二:什么是类: 类是模子,确定对象将会拥有的特征(属性)和行为(方法): 三:类的组成: 属性 ...
- node解析post表单信息
一共有4种解析方式 urlencoded.json.text .raw 发起请求的form表单中可以设置三种数据编码方式 application/x-www-form-urlencoded.multi ...
- Yarn 调度器Scheduler详解
理想情况下,我们应用对Yarn资源的请求应该立刻得到满足,但现实情况资源往往是有限的,特别是在一个很繁忙的集群,一个应用资源的请求经常需要等待一段时间才能的到相应的资源.在Yarn中,负责给应用分配资 ...
- C#导出数据到CSV和EXCEL文件时数字文本被转义的解决方法
今天写C#导出datagrid数据到csv格式文件的时候,发现不管怎么尝试,凡是单元格里面全是数字的单元格,在用Excel打开的时候,都被自动转义成数据格式.数据查看极其不方便.最后google了一下 ...
- Windows扩展屏开发总结
本文来自网易云社区 作者:梁敏 一.多屏设置 在设置-系统-可以点击显示器1和2,可以进行单独设置: "使之成为我的主显示器"可以设置当前显示器是主屏:主屏的选择会决定整个虚拟屏幕 ...
- Bootstrap开发漂亮的前端界面之实现原理
引:Bootstrap采用的是一个“响应式”设计.响应式Web 设计是一个让用户通过各种尺寸的设备浏览网站获得良好的视觉效果的方法.例如,您先在计算机显示器上浏览一个网站,然后再智能手机上浏览,智能手 ...
- MediaTypeListWidget->insertItem 添加的label没有填充单元格
label没有填充满当前的item,但是主界面拉伸或者大小变化之后会填充当前的item 类似相关的问题我猜测都是因为子控件或者需要参考的控件的参考对象的大小在初始化的时候还没有完成最终的初始化,导致大 ...
- 基于jersey和Apache Tomcat构建Restful Web服务(二)
基于jersey和Apache Tomcat构建Restful Web服务(二) 上篇博客介绍了REST以及Jersey并使用其搭建了一个简单的“Hello World”,那么本次呢,再来点有趣的东西 ...
- Leetcode代码补全——二叉树
在刷leetcode的过程中发现,在原网页输入答案是不需要自己构筑树和链表的,虽然便于直接思考算法,但是久而久之类似过于依赖编辑器,反而不知道如何创建树和链表,因此总结了该网页省略的部分,以其中题为例 ...
- python 学习总结----正则表达式
正则表达式 应用场景 - 特定规律字符串的查找,切割,替换 - 邮箱格式:URl,IP地址等的校验 - 爬虫项目中,特定内容的提取 使用原则 - 只要使用字符串等函数能解决的问题,就不要使用正则 - ...