链接:

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;
}

最新文章

  1. web网站 Vs 移动App 谁更能打动你?之 产品经理篇
  2. 引入Ember插件 大概流程
  3. js写当鼠标悬浮及移开出现背景变化
  4. JAVA线程锁-读写锁应用,简单的缓存系统
  5. [转自51CTO]ITIL与ISO20000的关系
  6. [Java解惑]应用
  7. [saiku] 通过 saiku 的 DEMO 分析 connection
  8. php部分---对数据的多条件查询,批量删除
  9. 2014年10月16号--for语句实例
  10. HDU2527:Safe Or Unsafe(哈弗曼树)
  11. android usb挂载分析---MountService启动
  12. ACM学习之路__HDU 1045
  13. oracle case when及decode的用法
  14. Egret的容器--删除对象,遮罩
  15. 学习笔记CB011:lucene搜索引擎库、IKAnalyzer中文切词工具、检索服务、查询索引、导流、word2vec
  16. 基于Docker搭建MySQL多源复制环境
  17. C语言程序设计II—第八周教学
  18. BZOJ4383 Pustynia(线段树+拓扑排序)
  19. Zephir入门教程一
  20. ArcGIS案例学习笔记1_1

热门文章

  1. java:Springmvc框架1(基本配置,注解配置,转换器引入)
  2. Arouter核心思路和源码
  3. Microsoft Remote Desktop for Mac
  4. 【LeetCode】714、买卖股票的最佳时机含手续费
  5. 【VS开发】【图像处理】RGB Bayer Color分析
  6. Java 并发编程:核心理论(一)
  7. Akka系列(十):Akka集群之Akka Cluster
  8. redis主从+哨兵模式(借鉴)
  9. PhpStorm配置Xdebug调试
  10. 小白学习django第三站-自定义过滤器及标签