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 ( 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
#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种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
随机推荐
- 如何搭建http服务仓库
1.拷贝仓库repo-A文件到服务器/media/D: 2.通过createrepo_c 生成仓库rpm信息数据 cd repo-A createrepo . 3.chmod -R 775 repo ...
- UIImageView中的UIButton不响应事件解决方案
如下: CGRect imageRect = (CGRect){, , , }; UIImageView *imageView = [[[UIImageView alloc] initWithFram ...
- ApplicationContext(三)BeanFactory 初始化
ApplicationContext(三)BeanFactory 初始化 上节我们提到容器初始化的第一步首先进行了属性的检验,下面就要开始第二步:进行 beanFactory 的初始化工作了. App ...
- Activiti任务认领
Activiti任务认领 TaskService taskService; taskService.setAssignee(String taskId, String userId);taskServ ...
- MMS从Contacts中添加收件人显示email账号
android系统默认代码,MMS中可以添加email地址作为收件人,但是从Contacts中选择收件人时却不显示email. 解决思路:为了降低修改量,在原来只搜索phoneNum的基础上,再做一次 ...
- Java环境编写
首先安装jdk,本系统中jdk安装在D:\jdk:jre安装在D:\Jre: 然后开始配置环境变量: JAVA_HOME:D:\jdk; JRE_HOME:D:\jre; CLASSPATH:.;%J ...
- @Valid报错 No validator could be found for constraint
使用hibernate validator出现上面的错误, 需要 注意 @NotNull 和 @NotEmpty 和@NotBlank 区别 @NotEmpty 用在集合类上面@NotBlank 用 ...
- Java第3章笔记
if基本语法: if(条件){// 表达式 // 代码块 } eg: int a = 10; if(a > 1){ System.out.println("内容& ...
- Query - noConflict() 方法
ps:菜鸟教程 如何在页面上同时使用 jQuery 和其他框架? noConflict() 方法会释放对 $ 标识符的控制,这样其他脚本就可以使用它了. 当然,您仍然可以通过全名替代简写的方式来使用 ...
- poj-2777(区间线段树,求种类数模板)
题目链接:http://poj.org/problem?id=2777 参考文章:https://blog.csdn.net/heucodesong/article/details/81038360 ...