Oil Skimming

Problem 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
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4186 4177 4178 4180 4181 
 

————————————————————————————————————

题目的意思是给出一张图#表示油田,用1*2的矩阵去盖在#上,问最多可以放多少个#

思路:题目就是拿行列和为奇数的点和行列和为偶的点匹配,问最多可以多少,图大hash一下

其实复杂度还是绷不住,我也没什么思路,但看了网上的都是直接上,数据水了

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int ha[MAXN][MAXN];
char s[MAXN];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,n,k,x,y,T;
int q=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); int cnt=0;
memset(ha,-1,sizeof ha);
for(int i=0; i<n; i++)
{
scanf("%s",s);
for(int j=0; j<n; j++)
{
if(s[j]=='#')
ha[i][j]=cnt++;
}
}
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(ha[i][j]!=-1)
{
for(int k=0; k<4; k++)
{
int xx=i+dir[k][0];
int yy=j+dir[k][1];
if(xx>=0&&xx<n&&yy>=0&&yy<n&&ha[xx][yy]!=-1)
{
g[ha[i][j]][ha[xx][yy]]=1;
}
} }
uN=vN=cnt;
printf("Case %d: %d\n",q++,hungary()/2); }
return 0;
}

Hdu4185 Oil Skimming的更多相关文章

  1. HDU4185 Oil Skimming —— 最大匹配

    题目链接:https://vjudge.net/problem/HDU-4185 Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  2. 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)

    如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...

  3. HDU4185 Oil Skimming 二分图匹配 匈牙利算法

    原文链接http://www.cnblogs.com/zhouzhendong/p/8231146.html 题目传送门 - HDU4185 题意概括 每次恰好覆盖相邻的两个#,不能重复,求最大覆盖次 ...

  4. hdu4185 Oil Skimming(偶匹配)

    <span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...

  5. HDU4185:Oil Skimming(二分图最大匹配)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

  7. J - Oil Skimming 二分图的最大匹配

    Description Thanks to a certain "green" resources company, there is a new profitable indus ...

  8. Oil Skimming HDU - 4185(匹配板题)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】

    Oil Skimming Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

随机推荐

  1. linux操作系统-设置静态ip

    在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [root@localhost ...

  2. js的面向对象

    JavaScript不区分类和实例的概念,而是通过原型(prototype)来实现面向对象编程. 原型是指当我们想要创建xiaoming这个具体的学生时,我们并没有一个Student类型可用 var ...

  3. Liunx touch

    http://blog.csdn.net/tanga842428/article/category/6355419 linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时 ...

  4. mybatis入门--mapper代理方式开发

    不使用代理开发 之前,我们说了如何搭建mybatis框架以及我们使用mybatis进行简单的增删改查.现在,我们一起来构建一个dao层的完整代码.并用@test来模拟service层对dao层进行一下 ...

  5. js的日期格式判断

    var reg = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; var str = (new Date).toLocaleString() ...

  6. POJ 2762 Going from u to v or from v to u?- Tarjan

    Description 判断一个有向图是否对于任意两点 $x$,  $y$ 都有一条路径使$x - >y$或 $y - >x$ Solution 对于一个强联通分量内的点 都是可以互相到达 ...

  7. 201621123008 《Java 程序设计》 第九周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...

  8. django数据库多对多修改对应关系

    obj = models.Book.objects.get(id=1) #添加对应关系,给书添加作者# obj.m.add(3)# obj.m.add(2,4)# obj.m.add(*[1,2,3, ...

  9. 约束 CONSTRAINT

    约束用于限制加入表中数据的类型 约束的种类: 非空约束(NOT NULL):约束列不接受NULL值,强制字段始终包含值. 唯一约束(UNIQUE):约束一列或一组列中的数据是唯一的.表中可以有多个唯一 ...

  10. 2017/2/13:springMVC拦截器的使用

    一.定义Interceptor实现类(主要是实现Handlerceptor接口) SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的.在Spr ...