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 ...
随机推荐
- Java学习之==>常用字符串方法
1.定义字符串 // 定义, 为初始化 String str1; // 定义, 并初始化为null String str2 = null; // 定义, 并初始化为空串 String str3 = & ...
- Linux监控命令之==>ps
一.命令说明 ps 命令是最基本同时也是非常强大的进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程是否结束.进程有没有僵死.哪些进程占用了过多的资源等等.总之大部分信息都是可以通过 ...
- python实现矩阵乘法的方法
python实现矩阵乘法的方法 本文实例讲述了python实现矩阵乘法的方法.分享给大家供大家参考. 具体实现方法如下: def matrixMul(A, B): res = [[0] * l ...
- Stream parallel并行流的思考
1.并行流并不一定能提高效率,就和多线程并不能提高线程的效率一样 因为引入并行流会引起额外的开销,就像线程的频繁上下文切换会导致额外的性能开销一样,当数据在多个cpu中的处理时间小于内核之间的传输时间 ...
- multiplication_puzzle(区间dp)
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 使用lombok.Data编译时无法找到get/set方法
我的IDEA版本是2019.2 在使用IDEA创建了一个SpringBoot项目,其中一个实体类使用了@Data注解,但是在Service中调用的时候找不到get/set方法. 检查步骤: 1.在St ...
- 三校联训 小澳的葫芦(calabash) 题解
题面:小澳的葫芦[ 题目描述]小澳最喜欢的歌曲就是<葫芦娃>.一日表演唱歌,他尽了洪荒之力,唱响心中圣歌.随之,小澳进入了葫芦世界.葫芦世界有 n 个葫芦,标号为 1~ n. n 个葫芦由 ...
- Hdu 4738【tanjan求无向图的桥】割边判定定理 dfn[x] < low[y]
题目: 曹操在长江上建立了一些点,点之间有一些边连着.如果这些点构成的无向图变成了连通图,那么曹操就无敌了.刘备为了防止曹操变得无敌,就打算去摧毁连接曹操的点的桥.但是诸葛亮把所有炸弹都带走了,只留下 ...
- P1397 [NOI2013]矩阵游戏
传送门 首先显然可以矩乘快速幂然后 $T$ 飞 看一眼题解发现因为这一题矩阵的特殊性所以可以对矩阵的次数欧拉降幂 然而我并不懂证明,所以我选择暴力乱搞的做法 十进制快速幂,然后注意一下常数,还有矩阵乘 ...
- ElasticSearch基础知识讲解
第一节 ElasticSearch概述 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTfull web接口.ElasticSea ...