HDU-4185-Oil Skimming(最大匹配)
链接:
https://vjudge.net/problem/HDU-4185
题意:
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.
思路:
给每个#号标记编号,在对每个#号周围选择相邻的配对,最大匹配。
答案除2.
代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN = 1e3+10;
const int INF = 1<<30;
int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char Map[MAXN][MAXN];
int Dis[MAXN][MAXN];
vector<int> G[MAXN*MAXN];
int Linked[MAXN], Vis[MAXN];
int n, cnt;
bool Dfs(int x)
{
for (int i = 0;i < G[x].size();i++)
{
int node = G[x][i];
if (Vis[node])
continue;
Vis[node] = 1;
if (Linked[node] == -1 || Dfs(Linked[node]))
{
Linked[node] = x;
return true;
}
}
return false;
}
int Solve()
{
memset(Linked, -1, sizeof(Linked));
int sum = 0;
for (int i = 1;i <= cnt;i++)
{
memset(Vis, 0, sizeof(Vis));
if (Dfs(i))
sum++;
}
return sum;
}
int main()
{
int t, times = 0;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = 1;i <= n;i++)
scanf("%s", Map[i]+1);
cnt = 0;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
if (Map[i][j] == '#')
Dis[i][j] = ++cnt;
}
for (int i = 1;i <= cnt;i++)
G[i].clear();
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
if (Map[i][j] == '#')
{
for (int k = 0;k < 4;k++)
{
int tx = i+Next[k][0];
int ty = j+Next[k][1];
if (tx < 1 || tx > n || ty < 1 || ty > n)
continue;
if (Map[tx][ty] == '#')
G[Dis[i][j]].push_back(Dis[tx][ty]);
}
}
}
int sum = Solve();
printf("Case %d: %d\n", ++times, sum/2);
}
return 0;
}
HDU-4185-Oil Skimming(最大匹配)的更多相关文章
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- HDU 4185 Oil Skimming 【最大匹配】
<题目链接> 题目大意: 给你一张图,图中有 '*' , '.' 两点,现在每次覆盖相邻的两个 '#' ,问最多能够覆盖几次. 解题分析: 无向图二分匹配的模板题,每个'#'点与周围四个方 ...
- 4185 Oil Skimming 最大匹配 奇偶建图
题目大意: 统计相邻(上下左右)的‘#’的对数. 解法: 与题目hdu1507 Uncle Tom's Inherited Land*类似,需要用奇偶建图.就是行+列为奇数的作为X集合,偶尔作为Y集合 ...
- HDU 4185 Oil Skimming
题目大意:在一个N*N的矩阵里寻找最多有多少个“##”(横着竖着都行). 题目分析:重新构图,直接以相邻的两个油井算中间算以条边,然后进行匹配,看看两两之间最多能匹配多少对. #include ...
- HDU4185 Oil Skimming —— 最大匹配
题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memo ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 匈牙利算法求最大匹配(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 ...
随机推荐
- 问题:anaconda: command not found
打开Terminal 1.使用命令:sudo apt install vim 安装vim文本编辑器2.使用命令:vim ~/.bashrc 修改环境变量 3.在文本最后添加命令:export PATH ...
- Oracle中 ORA-12704:字符集不匹配
前言 在使用Union all连接时,若A集合中某列为nvarchar2或nvarchar类型,而B集合中无此列,用‘ ’ 来代替是会报字符集不匹配 1 select '中国','China',cas ...
- 如何在 Spring/Spring Boot 中做参数校验
数据的校验的重要性就不用说了,即使在前端对数据进行校验的情况下,我们还是要对传入后端的数据再进行一遍校验,避免用户绕过浏览器直接通过一些 HTTP 工具直接向后端请求一些违法数据. 本文结合自己在项目 ...
- 【Qt开发】QT中用函数把float转化成QString
QT中用函数把float转化成QString 最普通的用法,例如: float f; QString str = QString("float is %1").ar ...
- Redis配置主从时报错“Could not connect to Redis at 192.168.0.50:6379: Connection refused not connected>”
配置Redis主从时,修改完从节点配置文件,然后报错 [root@Rich七哥-0-50 redis]# /opt/redis/redis-cli -h 192.168.0.50 Could not ...
- (2.2)【转】mysql的SQL笔记
一千行 MySQL 详细学习笔记 IT技术思维 4月1日 ↑↑↑点上方蓝字关注并星标⭐「IT技术思维」 一起培养顶尖技术思维 作者:格物 原文链接:https://shockerli.net/post ...
- SpringMVC上传文件总结
如果是maven项目 需要在pom.xml文件里面引入下面两个jar包 <dependency> <groupId>commons-fileupload</groupId ...
- [UER #1] DZY Loves Graph
题目描述 开始有 \(n\) 个点,现在对这 \(n\) 个点进行了 \(m\) 次操作,对于第 \(i\) 个操作(从 \(1\) 开始编号)有可能的三种情况: \(Add\) a b: 表示在 \ ...
- 2017.9.23 C组比赛总结
今天又回到了C组,感觉爽歪歪~分数终于是个三位数了,yes! 第一题,赛车.水!只用一个贪心就可以AC了. first,以速度为关键字小到大qsort一下... scond,枚举每一个赛车,看看它可以 ...
- ExpressionToSQL
ExpressionToSql using System; using System.Collections.Generic; using System.Collections.ObjectModel ...