链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4185

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#problem/G

与上题(H)相似

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 510
#define INF 0x3f3f3f3f // un是匹配左边的定点数, vn是匹配右边的定点数
int n, un, vn, used[N], p[N], Hash[N][N], g[N][N];
char G[N][N]; //匈牙利算法, 从左边开始找增广路
int Find(int u)
{
for(int j=; j<vn; j++)
{
if(!used[j] && g[u][j])
{
used[j] = ;
if(p[j]==- || Find(p[j]))
{
p[j] = u;
return true;
}
}
}
return false;
} //最大匹配数
int hungary()
{
int ans = ; memset(p, -, sizeof(p));
for(int i=; i<un; i++)
{
memset(used, , sizeof(used));
if(Find(i)) ans++;
}
return ans;
} int main()
{
int t, k=;
scanf("%d", &t);
while(t--)
{
int i, j, tol=; scanf("%d", &n);
memset(G, , sizeof(G));
memset(Hash, , sizeof(Hash));
memset(g, , sizeof(g)); for(i=; i<n; i++)
{
scanf("%s", G[i]);
for(j=; j<n; j++)
if(G[i][j]=='#')
Hash[i][j]=tol++;
} for(i=; i<n; i++)
for(j=; j<n; j++)
{
if(G[i][j]=='#')
{
if(i> && G[i-][j]=='#') g[Hash[i][j]][Hash[i-][j]]=;
if(i<n- && G[i+][j]=='#') g[Hash[i][j]][Hash[i+][j]]=;
if(j> && G[i][j-]=='#') g[Hash[i][j]][Hash[i][j-]]=;
if(j<n- && G[i][j+]=='#') g[Hash[i][j]][Hash[i][j+]]=;
}
} un = vn = tol;
printf("Case %d: %d\n", k++, hungary()/); }
return ;
}

(匹配)Oil Skimming -- hdu --4185的更多相关文章

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

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

  2. G - Oil Skimming - hdu 4185(二分图匹配)

    题意:在大海里有一些石油 ‘#’表示石油, ‘.’表示水,有个人有一个工具可以回收这些石油,不过只能回收1*2大小的石油块,里面不能含有海水,要不就没办法使用了,求出来最多能回收多少块石油 分析:先把 ...

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

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

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

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

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

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

  6. Hdu4185 Oil Skimming

    Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...

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

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

  8. H - Oil Skimming (挖石油)

    题意大概是,海上漂浮着一些符号为#的石油,你要去搜集他们,但是你的勺子呢能且只能挖到两个单元的石油.问你最多能挖多少勺.注意 不能挖到纯净的海水,不然石油会被纯净的海水稀释的. 二分匹配,计算出里边有 ...

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

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

随机推荐

  1. (转载)session token机制

    http://blog.chinaunix.net/uid-26642709-id-3061264.html 使用session token时,必须用struts2表标签库,不能用html 通过ses ...

  2. Haskell语言学习笔记(40)Arrow(1)

    Arrow class Category a => Arrow a where arr :: (b -> c) -> a b c first :: a b c -> a (b, ...

  3. scala--函数式对象

    函数式对象 这次写点关于函数式对象的吧 class Rational(n:Int, d:Int) { // n,d 为类参数,scala会创造出同样带有这两个参数的主构造器.如果这个类没有主体,可以不 ...

  4. 吴裕雄 数据挖掘与分析案例实战(7)——岭回归与LASSO回归模型

    # 导入第三方模块import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom sklearn import mod ...

  5. MySQL高级-索引

    1.索引是什么 索引(Index)是帮助MySQL高效获取数据的数据结构.可以得到索引的本质:索引是数据结构. 可以理解为“排好序的快速查找数据结构” 在数据之外,数据库系统还维护着满足特定查找算法的 ...

  6. JPA报错, PersistenceException_Unable to build Hibernate SessionFactory

    javax.persistence.PersistenceException: [PersistenceUnit: TestJPA] Unable to build Hibernate Session ...

  7. Struct2总结

    摘自<javaWeb整合开发王者归来> 一.Struct2工作流程 1.访问jsp页面  /struts2/login.jsp 2.提交表单后数据提交给 /struts2/loginPer ...

  8. INI

    .ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式,统管windows的各项配置,一般用户就用windows提供的各项图形化管理 ...

  9. 139. Word Break (String; DP)

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  10. SVN概述

    ----------------------siwuxie095                                 SVN 概述         1.SVN 即 Subversion 的 ...