[BZOJ 1735] Muddy Fields
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=1735
[算法]
二分图最小覆盖
[代码]
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1010 struct edge
{
int to,nxt;
} e[MAXN * MAXN]; int i,j,n,m,ans,cntx,cnty,tot;
char mp[MAXN][MAXN];
int x[MAXN][MAXN],y[MAXN][MAXN];
int match[MAXN],head[MAXN];
bool visited[MAXN]; inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
}
inline bool hungary(int u)
{
int i,v;
for (i = head[u]; i; i = e[i].nxt)
{
v = e[i].to;
if (!visited[v])
{
visited[v] = true;
if (!match[v] || hungary(match[v]))
{
match[v] = u;
return true;
}
}
}
return false;
} int main()
{ scanf("%d%d",&n,&m);
for (i = ; i <= n; i++) scanf("%s",mp[i] + );
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
if (mp[i][j] == '*')
{
x[i][j] = ++cntx;
while (j < m && mp[i][j + ] == '*')
{
j++;
x[i][j] = cntx;
}
}
}
}
for (j = ; j <= m; j++)
{
for (i = ; i <= n; i++)
{
if (mp[i][j] == '*')
{
y[i][j] = ++cnty;
while (i < n && mp[i + ][j] == '*')
{
i++;
y[i][j] = cnty;
}
}
}
}
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
if (mp[i][j] == '*')
addedge(x[i][j],y[i][j]);
}
}
for (i = ; i <= cntx; i++)
{
memset(visited,false,sizeof(visited));
if (hungary(i)) ans++;
}
printf("%d\n",ans); return ; }
[BZOJ 1735] Muddy Fields的更多相关文章
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- poj 2226 Muddy Fields(最小覆盖点+构图)
http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2226 Muddy Fields (转化成二分图的最小覆盖)
http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2226 Muddy Fields(最小顶点覆盖)
POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...
- Muddy Fields
Muddy Fields Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- poj 2226 Muddy Fields (二分匹配)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7340 Accepted: 2715 Desc ...
- poj Muddy Fields
Muddy Fields 原题去我创的专题里找,在文件夹首页. 题目: 给出N*M矩阵.当中*表示泥土,.表示小草.要你用最少的木板把泥土覆盖. 木板长度不限.可是仅仅能水平和竖直. 行列式二分匹配配 ...
- BNUOJ 2345 Muddy Fields
Muddy Fields Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...
- POJ Muddy Fields 泥泞的牧场 二分图
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13235 Accepted: 4879 汪星人 ...
随机推荐
- JS高级——静态成员与实例成员
静态成员:构造函数的属性和方法 实例成员:实例化之后对象的属性和方法 // $("#id").css(); // $("#id").text(); // $.t ...
- mysql幻读
开启a,b两个数据库连接,a.b都开启事务后,b插入了一条数据R并提交,验证对a的操作造成的影响 select select for update update R update R 后 select ...
- 从ABC到流利口语-unit01
Unit 1 Introduction1 Good evening,everyone.It's a pleasure to you all. My name is Wang Dong.I'M from ...
- CaffeMFC:caffe.pb.h(2525): error C2059: syntax error : 'constant'
下边的语句会报 syntax error : 'constant'. static const DimCheckMode STRICT = V1LayerParameter_DimCheckMode_ ...
- (转) 分布式文件存储FastDFS(七)FastDFS配置文件详解
http://blog.csdn.net/xingjiarong/article/details/50752586 配置FastDFS时,修改配置文件是很重要的一个步骤,理解配置文件中每一项的意义更加 ...
- IOS7 APP 升级的10个TIP 建议
There is no way to preserve the iOS 6 style status bar layout. The status bar will always overlap yo ...
- 谷歌通过ajax获取本地JSON文件,为什么会提示跨域?
在本地写了一段JSON代码,然后用ajax读取后,在浏览器打开,发现谷歌提示涉及到跨域问题, 但是跨域是由于协议,域名,端口中有一个不同,才会跨域,我在本地访问自己的文件,怎么和跨域扯上关系了?? 下 ...
- 【原】Pchart生成图片
学习网址: http://wiki.pchart.net/doc.introduction.html http://pchart.sourceforge.net/index.php
- Thesis Viva checklist
This list gives you suggestions helpful in preparing to defend your thesis: I know my thesis thoroug ...
- PAT 1108 Finding Average
The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...