(匹配)Oil Skimming -- hdu --4185
链接:
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的更多相关文章
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- G - Oil Skimming - hdu 4185(二分图匹配)
题意:在大海里有一些石油 ‘#’表示石油, ‘.’表示水,有个人有一个工具可以回收这些石油,不过只能回收1*2大小的石油块,里面不能含有海水,要不就没办法使用了,求出来最多能回收多少块石油 分析:先把 ...
- hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)
Problem Description Thanks to a certain "green" resources company, there is a new profitab ...
- HDU 4185 ——Oil Skimming——————【最大匹配、方格的奇偶性建图】
Oil Skimming Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU4185:Oil Skimming(二分图最大匹配)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Hdu4185 Oil Skimming
Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...
- 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)
如下图:要求最多可以凑成多少对对象 大佬博客: https://blog.csdn.net/cillyb/article/details/55511666 https://blog.csdn.net/ ...
- H - Oil Skimming (挖石油)
题意大概是,海上漂浮着一些符号为#的石油,你要去搜集他们,但是你的勺子呢能且只能挖到两个单元的石油.问你最多能挖多少勺.注意 不能挖到纯净的海水,不然石油会被纯净的海水稀释的. 二分匹配,计算出里边有 ...
- J - Oil Skimming 二分图的最大匹配
Description Thanks to a certain "green" resources company, there is a new profitable indus ...
随机推荐
- UIButton 点击事件传参数
#import <objc/runtime.h> UIButton *btn = // create the button objc_setAssociatedObject(btn, &q ...
- 面向对象三大特性一一继承(inheritance)和组合(Composition)
记住2句话(常识),像个正常人思考! 1.“ is-a ”关系 用 继承! 学生是人,学生继承人这个类, 2. “has-a ”关系 用 组合!电脑有显卡,那么我们就在计算机类中增加显卡属性来复用显 ...
- SO\PR回写的数据如下
insert into OUT_ORDER_RES ---JAVA FOR PR ) as LGORT ,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so ...
- golang 打印变量类型
fmt.Println("type:", reflect.TypeOf(err.Error()))
- V4 V7 V13支持包的区别
三者均为支持包,可以让低版本系统使用高版本特性,支持最小版本有差异 V4支持1.6以上 V7支持2.1以上 V13支持3.2以上 V7依赖V4
- java线程状态及转换
java线程有6种状态: 新建线程new,启动线程runnable,阻塞block,限时等待timed_waiting,等待线程waiting,终止线程terminated 1.限时等待timed w ...
- 每月IT摘录201805
摘录自互联网的前辈心得: 一.技术:0.精通一个淘汰的技术对你没有任何价值.学习的精力有限,更应该花在值得学的技术上.比如网络.操作系统.数据结构.算法1.工作要有定力,更多的应该是关心问题如何更有效 ...
- 1.Two Sum (Array; HashTable)
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- [leetcode]299. Bulls and Cows公牛和母牛
You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...
- Paypal支付
<!--Paypal支付数据开始--> <input type="hidden" name="charset" value="utf ...