J - Oil Skimming 二分图的最大匹配
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 ( 1K
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
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std; #define N 1210
int cx[N];
int cy[N];
int nx,ny;
int mk[N];
vector<int> map[N];
int ma[N][N];
char g[][]; int path(int u)
{
int len = map[u].size();
for(int i = ; i < len; i ++)
{
int v = map[u][i];
if(!mk[v])
{
mk[v] = ;
if(cy[v] == - || path(cy[v])) ///cy #号块也没有动||cy 也有符合条件的
{
cx[u] = v;
cy[v] = u;
return ;
} }
}
return ;
}
int maxma()
{
int res = ;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
for(int i = ; i < nx; i ++)
{
if(cx[i] == -) ///#号块儿 没动
{
memset(mk,,sizeof(mk));
res += path(i);
//printf("%d---\n",res);
}
}
return res;
}
int main()
{
int t,n;memset(g,,sizeof(g));
//freopen("a.txt","r",stdin);
scanf("%d",&t);
int ca = ;
while(t--)
{
scanf("%d",&n);
for(int i = ;i <= n*n;i ++)
map[i].clear(); ///初始化
int num = ;
//memset(map,0,sizeof(map));
for(int i = ; i <= n; i ++)
{
scanf("%s",g[i]+);
for(int j = ;j <= n;j ++)
if(g[i][j]=='#') ma[i][j] = num++; ///多少#
//printf("||%s\n",g[i]+1);
}
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++) ///符合条件的
{
if(g[i][j] != '#') continue;
if(g[i][j] == '#' && '#' == g[i+][j])
map[ma[i][j]].push_back(ma[i+][j]);
if(g[i][j] == '#' && g[i-][j] == '#')
map[ma[i][j]].push_back(ma[i-][j]);
if(g[i][j] == '#' && g[i][j+] == '#')
map[ma[i][j]].push_back(ma[i][j+]);
if(g[i][j] == '#' && g[i][j-] == '#')
map[ma[i][j]].push_back(ma[i][j-]);
}
nx = ny = num;
printf("Case %d: %d\n",ca++,maxma()/);
}
return ;
}
J - Oil Skimming 二分图的最大匹配的更多相关文章
- HDU4185 Oil Skimming 二分图匹配 匈牙利算法
原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 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/ ...
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu3729 I'm Telling the Truth (二分图的最大匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...
- POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)
题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
随机推荐
- @1-4使用Xpath解析豆瓣短评
使用Xpath解析豆瓣短评 Python爬虫(入门+进阶) DC学院 本节课程主要介绍解析神器Xpath是什么.Xpath如何安装及使用,以及使用实际的例子讲解Xpath如何解析豆瓣短评的网页 ...
- unity luaFramework
1 AppConst: DebugMode: 调试模式,true:lua脚本直接读取自 AssetDir,false:开始会将AssetDir内的lua脚本复制到 Util.DataPath内(根据平 ...
- HttpURLConnection 返回汉字乱码(全是问号)
public static String doPost(String urlStr, Map<String, Object> paramMap) throws Exception { UR ...
- Java学习笔记:知识总结
概述 1991年由sun公司开发的名称为Oak的语言,1994年更名为Java. JDK:Java Development Kit,Java的开发和运行环境,Java的开发工具和JRE. JRE:Ja ...
- SparkStreaming--reduceByKeyAndWindow
1.reduceByKeyAndWindow(_+_,Seconds(3), Seconds(2)) 可以看到我们定义的window窗口大小Seconds(3s) ,是指每2s滑动时,需要统计 ...
- java15
1.数组 格式:数据类型 [ ] 数据名称 = new 数据类型 [ ] { }: 2.初始化 静态初始化(已知要开多少个房间来存储数据) int[ ] a =new int[ ] {12,32,54 ...
- HTML-入门篇day01
HTML-入门篇day01 1.web C/S:Client Server 客户端 服务器 QQ,... B/S:Browser Server 浏览器 服务器 PC机: ...
- 2018.11.05 bzoj2143: 飞飞侠(最短路)
传送门 最短路好题. 考虑对每个二维坐标建立一个高度属性. 这样每次如果在点(i,j,0)(i,j,0)(i,j,0)只能选择花费bi,jb_{i,j}bi,j跳向(i,j,ai,j)(i,j,a_ ...
- Java对象的克隆
今天要介绍一个概念,对象的克隆.本篇有一定难度,请先做好心理准备.看不懂的话可以多看两遍,还是不懂的话,可以在下方留言,我会看情况进行修改和补充. 克隆,自然就是将对象重新复制一份,那为什么要用克隆呢 ...
- JSAAS 平台实现 微信类似的TOKEN机制
在企业微信中,我们在调用微信接口时,我们需要首先获取token,然后根据token,调用API接口方法.这个token是有生命周期的,微信的token默认的生命周期是7200秒. 因此这个token可 ...