POJ2226 Muddy Fields
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10149 | Accepted: 3783 |
Description
To prevent those muddy hooves, Farmer John will place a number of wooden boards over the muddy parts of the cows' field. Each of the boards is 1 unit wide, and can be any length long. Each board must be aligned parallel to one of the sides of the field.
Farmer John wishes to minimize the number of boards needed to cover the muddy spots, some of which might require more than one board to cover. The boards may not cover any grass and deprive the cows of grazing area but they can overlap each other.
Compute the minimum number of boards FJ requires to cover all the mud in the field.
Input
* Lines 2..R+1: Each line contains a string of C characters, with '*' representing a muddy patch, and '.' representing a grassy patch. No spaces are present.
Output
Sample Input
4 4
*.*.
.***
***.
..*.
Sample Output
4
Hint
Boards 1, 2, 3 and 4 are placed as follows:
1.2.
.333
444.
..2.
Board 2 overlaps boards 3 and 4.
Source
将连续的一段横/纵条算作同一个,若横纵条相交则连边,跑二分图匹配。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int m,n;
char a[mxn][mxn];
//
int idx,idy;
int hs[mxn][mxn];
int link[mxn];
int mp[mxn][mxn];
bool vis[mxn];
//
void init(){
int i,j;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(a[i][j]=='*'){
++idx;
while(a[i][j]=='*')hs[i][j++]=idx;
}
}
}
idy=idx;
for(j=;j<=m;j++)
for(i=;i<=n;i++){
if(a[i][j]=='*'){
++idy;
while(a[i][j]=='*'){
mp[idy][hs[i][j]]=;
mp[hs[i++][j]][idy]=;
}
}
}
return;
}
bool DFS(int u){
for(int i=;i<=idy;i++)
if(!vis[i] && mp[u][i]){
vis[i]=;
if(link[i]==- || DFS(link[i])){
link[i]=u;
return ;
}
}
return ;
}
int ans=;
void solve(){
memset(link,-,sizeof link);
for(int i=;i<=idx;i++){
memset(vis,,sizeof vis);
if(DFS(i))ans++;
}
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=n;i++)
scanf("%s",a[i]+);
init();
solve();
printf("%d\n",ans);
return ;
}
POJ2226 Muddy Fields的更多相关文章
- [USACO2005][POJ2226]Muddy Fields(二分图最小点覆盖)
题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...
- POJ2226 Muddy Fields(二分图最小点覆盖集)
题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...
- POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题
在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...
- poj2226 Muddy Fields 填充棒子(二分匹配)
参考博客:https://blog.csdn.net/liujc_/article/details/51287019 参考博客:https://blog.csdn.net/acdreamers/art ...
- 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 ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
随机推荐
- Jira-Clone与发邮件的使用
1.克隆问题 包括两部分,先进行Clone,再进行移动 a.选择要克隆的问题,点击More Actions-Clone,在弹出框“复制问题”中,点击“创建”按钮即克隆成功 b.移动问题,点击More ...
- Android优化——UI优化(五) Listview 重用convertView
1.重用convertView 我们对convertView添加判断,如果存在我们就直接使用,否则初始化一个convertView的实例.(如下图) 2.使用viewHolder 使用viewHold ...
- 微软职位内部推荐-UX Designer II
微软近期Open的职位: Search Technology Center Asia (STCA) Position: UX Designer Location: Beijing, China Sea ...
- [android界面]android中src和background区别——前景与背景
ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...
- 万向节死锁 gimbal lock
,如下图一,把灰色箭头想象成是一架飞机,红,绿蓝三个圈看作是三个外围控制器,外圈带动所有里圈运动,里圈的运动不影响外圈. 1,首先,绕Y轴旋转(旋转绿圈),来确定前进的方向.这时红圈与蓝圈都跟着旋转. ...
- Nginx支持连接数的问题
据网上有人说nginx的配置中: nginx支持的最大连接数与以下因素有关: worker_processes ; events { worker_connections ; } ulimit -a ...
- JS 之DOM range对象
DOM范围 DOM中的range对象是DOM2中新定义的接口.通过这个对象可以选择文档中的某个区域,而不必考虑节点的界限. 创建范围 document.createRange()创建一个范围,这个范围 ...
- Mininet建立topology zoo中的拓扑
以前用Mininet建立拓扑都是在别人的代码上进行需求上的修改,这次从头开始将topology zoo(http://www.topology-zoo.org/)中的拓扑用Mininet建立,不失一般 ...
- asp.net Core开启全新的时代,用视频来告诉你,学习就是这么SO easy。
https://channel9.msdn.com/Blogs/NET-Core/What-is-NET-Core 系统大家多发布一些视频的资料,学习起来更方便!我看到很多人发布的博客里面有的时候对于 ...
- 小白学习mysql之索引初步
导语 索引在数据库中的地位是及其的重要,同时要想完全的掌握索引并不是一件容易的事,需要对数据的查询原理以及计算机操作系统有深刻的认识,当然相关的算法和数据结构也是必须的.因此,这篇文章感到了一些压力, ...