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的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
随机推荐
- 使用log4j将日志写入数据库并发送邮件
参考: 快速了解Log4J 1.log4j的初始配置 参考该问的配置即可完整的实现写入数据库及发送邮件的功能 a.写入数据库需要配置相应的jar包,数据库类型不同,请使用指定的数据库配置,该文仅限于o ...
- python 线性回归示例
说明:此文的第一部分参考了这里 用python进行线性回归分析非常方便,有现成的库可以使用比如:numpy.linalog.lstsq例子.scipy.stats.linregress例子.panda ...
- 20145204&20145212信息安全系统实验四报告
20145204信息安全设计基础实验四报告 博客链接:信息安全设计基础实验
- poj1067-取石子游戏-wythoff博弈
打表找规律失败,搜了一下原来是wythoff博弈 /*------------------------------------------------------------------------- ...
- 20145222黄亚奇《Java程序设计》第9周学习总结
20145222第九周<Java学习笔记>学习总结 教材学习内容总结 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找 JDBC(Ja ...
- ViewController与outlet绑定
ViewController的作用 ViewController与XIB一一对应,用于分离独立出可重用组件单元,如单个组件.复合组件.界面片段.整个界面等. 通常继承 UIViewController ...
- 1.SQLAlchemy文档-简介(中文版)
Python的SQL工具包和对象关系映射器 SQLAlchemy的是Python的SQL工具包和对象关系映射器,让应用程序开发人员可以使用上SQL的强大功能和灵活性. 它提供了一套完整 ...
- 无光驱安装原版 windows server2008,win7 的方法,64位的。
这几天要对一台服务器进行安装 windows server2008的系统,64位.尼玛在网上买了一个光驱迟迟不到所以只能用U盘来了 以前安装ghost的系统U盘分分钟搞定.安装原版的iso文件遇到了一 ...
- C++成员权限控制(总结)
1) 前言 在我学习C++的过程中,类中成员的权限控制一直是比较头疼的一个点,一会public,一会又private,还有protected,再加点继承,而且又有公有继承.私有继承,保护继承,所以感觉 ...
- RockWare RockWorks的Ollydbg调试过程及注册机(破解)思路
最近拿到了RockWorks15的安装包,可惜没有破解,试用也只能用14天.用PEiD工具察看了一下,Delphi编写的程序,竟然没加壳.本想用OllyDBG调试进去爆破一下,不意发现注册码很简单,如 ...