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升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- Flutter制作Toast会自己关闭的消息提示框
项目中需要用到类似安卓的Toast提示框,因为flutter中又没有相关组件,然后在网上看到个不错的,地址https://www.jianshu.com/p/cf7877c9bdeb,然后拿过来修改了 ...
- 从char到QChar
char类型是c/c++中内置的类型,描述了1个字节的内存信息的解析.比如: char gemfield=’g’; 那么在由gemfield标记的这块内存的大小就是1个字节,信息就是01100111, ...
- margin padding border
Difference between margin and padding? Remember these 3 points: The Margin is the extra space around ...
- koa 项目实战(九)passport验证token
1.安装模块 npm install koa-passport -D npm install passport-jwt -D 2.解析token 根目录/config/passport.js cons ...
- ios 报错记录
1. 运行xcode 报错:unterminated conditional directive #ifdef 缺少对应的#endif 在结尾加上就好了 2.iOS添加非(c,c++)文件引发的&qu ...
- HmacSha1加密-java
package com.test; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache ...
- Django Model模型
Model简介 模型准确且唯一的描述了数据.它包含您储存的数据的重要字段和行为.一般来说,每一个模型都映射一张数据库表. 每个模型都是一个 Python 的类,这些类继承 django.db.mode ...
- CPU-内存-IO-网络调优
一.关于CPU 中央处理器调优 1. CPU处理方式: 批处理,顺序处理请求.(切换次数少,吞吐量大) 分时处理.(如同"独占",吞吐量小)(时间片,把请求分为一个一个的时间片,一 ...
- 关于XMind软件文件格式的一些思考
1,安装XMind软件,看见可以导入Markdown文件 2,因此新建了测试.md文件,代码格式为左图,显示效果为右图. 3,导入到XMind中显示为下图 4,也就是XMind中子标题对应着Markd ...
- maria 忘记密码
1.找到mariadb配置文件命令:find / -name my.cnf 备注:一般是在 /etc/my.cnf 2.修改配置文件 在MariaDB配置文件/etc/my.cnf的[mysqld]配 ...