题意:一片r*c的地,有些地方是泥地,需要铺地板。这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块

思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个id号,同样把竖的所有整体编号,这样一个点就有横竖两个编号,那么我给这两个编号连边,那么只要涂这个边就代表了这个点被模板盖住了,那么问题就转化为了最小点覆盖

思路:poj2226-Muddy Fields

代码:

#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
int linker[maxn];
bool used[maxn];
struct node{
int row, col;
}p[maxn][maxn];
int n;
int head[maxn], tot;
struct Edge{
int to, next;
}edge[maxn * maxn];
char mp[maxn][maxn];
void init(){
memset(head, -, sizeof(head));
tot = ;
}
void addEdge(int u, int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
bool dfs(int u){
for(int i = head[u]; i != -; i = edge[i].next){
int v = edge[i].to;
if(!used[v]){
used[v] = true;
if(linker[v] == - || dfs(linker[v])){
linker[v] = u;
return true;
}
}
}
return false;
}
int hungry(){
int res = ;
memset(linker, -, sizeof(linker));
for(int u = ; u <= n; u++){
memset(used, false, sizeof(used));
if(dfs(u)) res++;
}
return res;
}
int main(){
int r, c;
while(~scanf("%d%d", &r, &c)){
n = ;
init();
for(int i = ; i <= r; i++){
scanf("%s", mp[i] + );
for(int j = ; j <= c; j++){
p[i][j].col = p[i][j].row = ;
}
}
for(int i = ; i <= r; i++){
for(int j = ; j <= c; j++){
if(mp[i][j] == '*'){
if(j > && mp[i][j - ] == '*'){
p[i][j].row = p[i][j - ].row;
}
else{
p[i][j].row = ++n;
}
}
}
}
for(int i = ; i <= r; i++){
for(int j = ; j <= c; j++){
if(mp[i][j] == '*'){
if(i > && mp[i - ][j] == '*'){
p[i][j].col = p[i - ][j].col;
}
else{
p[i][j].col = ++n;
}
addEdge(p[i][j].row, p[i][j].col);
}
}
}
printf("%d\n", hungry());
}
return ;
}

POJ 2226 Muddy Fields(最小点覆盖)题解的更多相关文章

  1. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  2. POJ - 2226 Muddy Fields (最小顶点覆盖)

    *.*. .*** ***. ..*. 题意:有一个N*M的像素图,现在问最少能用几块1*k的木条覆盖所有的 * 点,k为>=1的任意值. 分析:和小行星那题很像.小行星那题是将一整行(列)看作 ...

  3. POJ 2226 Muddy Fields(最小顶点覆盖)

    POJ 2226 Muddy Fields 题目链接 题意:给定一个图,要求用纸片去覆盖'*'的位置.纸片能够重叠.可是不能放到'.'的位置,为最少须要几个纸片 思路:二分图匹配求最小点覆盖.和放车那 ...

  4. poj 2226 Muddy Fields (转化成二分图的最小覆盖)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  5. poj 2226 Muddy Fields(最小覆盖点+构图)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  6. [POJ] 2226 Muddy Fields(二分图最小点覆盖)

    题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...

  7. poj 2226 Muddy Fields(最小点覆盖+巧妙构图)

      Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= ...

  8. poj 2226 Muddy Fields(最小点覆盖)

    题意: M*N的矩阵,每个格不是*就是#.     *代表水坑,#代表草地. 农民要每次可以用一块宽为1,长不限的木板去铺这个矩阵.要求这块木板不能覆盖草地.木板可以重复覆盖(即一块木板与另一块木板有 ...

  9. POJ 2226 Muddy Fields (二分图匹配)

    [题目链接] http://poj.org/problem?id=2226 [题目大意] 给出一张图,上面有泥和草地,有泥的地方需要用1*k的木板覆盖, 有草地的地方不希望被覆盖,问在此条件下需要的最 ...

随机推荐

  1. Rpgmakermv(25) 游戏数据

    随着对RMMV插件了解的深入,我们会发现如果我们想要对游戏数据进行一些扩展,首先要了解游戏数据,游戏数据在官方代码中的rpg_managers.js里,这一节我们将要对这个官方类有一些基础的了解,并且 ...

  2. 【转】C#中base关键字的几种用法

    base其实最大的使用地方在面相对性开发的多态性上,base可以完成创建派生类实例时调用其基类构造函数或者调用基类上已被其他方法重写的方法.例如: 2.1关于base调用基类构造函数 public c ...

  3. 变量为空代表false

    name = ''#名字为空即代表False while not name:#not name=False即 真,将执行循环体 print('Enter your name:') name = inp ...

  4. orb slam2 双目摄像头

    主要参考了http://blog.csdn.net/awww797877/article/details/51171099这篇文章,其中需要添加的是:export ROS_PACKAGE_PATH=$ ...

  5. Class__Two

    今天老师要求做查找英文文章中最高频的词  文章用文本储存 import java.io.BufferedReader;import java.io.File;import java.io.FileIn ...

  6. mysql+servlet+jsp实现数据库的增删改查

    首先,了解数据库目前我们仅仅用来存放数据,在这里我们在数据库中生成一个表,包含id,classname,teacher,location.Tomcat用来配置eclipse,只有这样我们才能使用JSP ...

  7. 利用iOS中Safari浏览器创建伪Web App

    在safari浏览器里有一个“添加到主屏幕”选项,我们可以用来创建伪Web App,下面来了解一下iOS中Safari的私有属性 第一步设置Web App的主屏幕图标: 有两种属性值apple-tou ...

  8. vue之component

    因为组件是可复用的 Vue 实例,所以它们与 new Vue 接收相同的选项,例如 data.computed.watch.methods 以及生命周期钩子等.仅有的例外是像 el 这样根实例特有的选 ...

  9. HDU 3172 Virtual Friends (map+并查集)

    These days, you can do all sorts of things online. For example, you can use various websites to make ...

  10. nvidia-docker

    参考资料 https://github.com/NVIDIA/nvidia-docker/wiki/Installation#prerequisites https://github.com/NVID ...