poj 2226 Muddy Fields (二分图)
大意:给定n*m网格, 每个格子为泥地或草地, 可以用一些长度任意宽度为1的木板盖住泥地, 要求不能盖到草地, 求最少要多少块木板能盖住所有泥地.
最小点覆盖板子题, 建图跑最大匹配即可.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 110;
int n, m, clk, f[N*N], vis[N*N];
int col[N*N], raw[N*N], f1[N][N], f2[N][N];
vector<int> g[N*N];
char a[N][N];
int has(int i, int j) {return (i-1)*m+j;}
void add(int i, int j) {
g[i].pb(j),g[j].pb(i);
}
int dfs(int x) {
for (vector<int>::iterator it = g[x].begin(); it!=g[x].end(); ++it) {
int y = *it;
if (vis[y]!=clk) {
vis[y] = clk;
if (!f[y]||dfs(f[y])) return f[y]=x;
}
}
return 0;
}
int main() {
while (~scanf("%d%d", &n, &m)) {
REP(i,1,n) scanf("%s", a[i]+1);
*col = *raw = 0;
REP(i,1,2*n*m) f[i]=0,g[i].clear();
REP(i,1,n) {
REP(j,1,m) if (a[i][j]=='*') {
col[++*col] = has(i,j);
while (a[i][j]=='*') f1[i][j++]=col[*col];
--j;
}
}
REP(j,1,m) {
REP(i,1,n) if (a[i][j]=='*') {
raw[++*raw] = has(i,j)+has(n,m);
while (a[i][j]=='*') f2[i++][j]=raw[*raw];
--i;
}
}
REP(i,1,n) REP(j,1,m) if (a[i][j]=='*') add(f1[i][j],f2[i][j]);
int ans = 0;
REP(i,1,*col) {
++clk;
if (dfs(col[i])) ++ans;
}
printf("%d\n", ans);
}
}
poj 2226 Muddy Fields (二分图)的更多相关文章
- [POJ] 2226 Muddy Fields(二分图最小点覆盖)
题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...
- POJ 2226 Muddy Fields 二分图(难点在于建图)
题意:给定一个矩阵和它的N行M列,其中有一些地方有水,现在有一些长度任意,宽为1的木板,要求在板不跨越草,用一些木板盖住这些有水的地方,问至少需要几块板子? 思路:首先想到如果没有不准跨越草的条件则跟 ...
- POJ 2226 Muddy Fields(最小顶点覆盖)
POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...
- 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 (二分匹配)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7340 Accepted: 2715 Desc ...
- POJ 2226 Muddy Fields (二分图匹配)
[题目链接] http://poj.org/problem?id=2226 [题目大意] 给出一张图,上面有泥和草地,有泥的地方需要用1*k的木板覆盖, 有草地的地方不希望被覆盖,问在此条件下需要的最 ...
- poj 2226 Muddy Fields(水二分图)
Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- Tomcat的server.xml
慕课网:https://www.imooc.com/video/19201 Server:指整个tomcat服务器,它其中包含多个组件,它主要负责管理和启动各个service,同时监听8005端发过来 ...
- logserver 日志服务项目发布
logserver是使用logback.light-4j.commons-exec等构建的简单日志服务,参考项目logbackserver和light4j,支持跟踪日志.分页查看.搜索定位.下载文件等 ...
- iscc2018-Reverse-writeup
RSA256 解析公钥 yafu质因数分解 p=325045504186436346209877301320131277983 q=3028255367440967415185462127611943 ...
- R语言:各类型数据文件的导入
导入csv: read.csv() 导入txt: read.table() 注意,txt文件编码为unicode的导入r会报错,需转换成ANSI 读入excel:需要安装xlsx包,安装此包前先下载好 ...
- linux设备树中如何删除某个节点?
答:使用以下语法即可删除某节点: /delete-node/ 节点名;
- Ubuntu16.04.3安装并配置samba方法
目的:单个Linux用户可以在windows电脑上通过映射网络驱动器的方式来访问自己的工作目录. 方法如下: 1.安装smb服务器:apt-get install samba2.安装smb支持的文件系 ...
- Java访问Oracle服务器
Java访问Oracle服务器--orcl数据库---emp表 private static String driver = "oracle.jdbc.driver.Orac ...
- jar/war文件的解释
http://blog.csdn.net/tang_123_/article/details/6012202#comments
- R语言与概率统计(三) 多元统计分析(下)广义线性回归
广义线性回归 > life<-data.frame( + X1=c(2.5, 173, 119, 10, 502, 4, 14.4, 2, 40, 6.6, + 21.4, 2.8, 2. ...
- kettle转换和任务的基本使用
0 创建转换 并保存0816_em.ktr 1 主对象树中选择DB连接,创建2个DB连接 2 创建表输入 核心对象树中选择输入>表输入 3 核心对象树中选择输出>插入/更新表 并连线 4 ...