二分匹配的灵活运用

3041还是比较好想的,考虑到横排/竖排射一枪就能搞定这一行/一列的所有点,

我们以行数为点集x,列数为点集y,在目标点(xi,yi)之间连一条边

这样最小射击次数=最小点覆盖(边两端点至少有一个点在覆盖集中)=最大匹配

poj2226是它的加强版

这里一块木板不能覆盖非泥泞点,也就是说一块木板不一定能搞定那一行所有的点

于是我们考虑到将连续的泥泞点标号,表示这些泥泞点是由哪个木板盖住(横竖分别标号)

这样,我们以横排木板为点集x,竖排木板为点集y,对于每个点,在盖住它的横竖排木板之间连边

(显然,每个点至多被一个横木板,一个竖木板覆盖)

于是根据poj3041,做匈牙利即可

 var a:array[..,..] of char;
    h1,h2:array[..,..] of longint;
    map:array[..,..] of boolean;
    cx,cy:array[..] of longint;
    v:array[..] of boolean;
    s1,s2,ans,i,j,n,m:longint; function find(x:longint):longint;   //增广路
  var i:longint;
  begin
    for i:= to s2 do
      if map[x,i] and not v[i] then
      begin
        v[i]:=true;
        if (cy[i]=-) or (find(cy[i])>) then
        begin
          cx[x]:=i;
          cy[i]:=x;
          exit();
        end;
      end;
    exit();
  end; begin
  readln(n,m);
  for i:= to n do
  begin
    for j:= to m do
    begin
      read(a[i,j]);
    end;
    readln;
  end;
  for i:= to n do         //横排标号
  begin
    j:=;
    while j<=m do
    begin
      if a[i,j]='*' then
      begin
        inc(s1);
        h1[i,j]:=s1;
        inc(j);
        while a[i,j]='*' do     
        begin
          h1[i,j]:=s1;
          inc(j);
        end;
      end
      else inc(j);
    end;
  end;
  for i:= to m do      //竖排标号
  begin
    j:=;
    while j<=n do
    begin
      if a[j,i]='*' then
      begin
        inc(s2);
        h2[j,i]:=s2;
        inc(j);
        while a[j,i]='*' do
        begin
          h2[j,i]:=s2;
          inc(j);
        end;
      end
      else inc(j);
    end;
  end;
  for i:= to n do
    for j:= to m do
      map[h1[i,j],h2[i,j]]:=true;    //连边
  fillchar(cx,sizeof(cx),);
  fillchar(cy,sizeof(cy),);
  for i:= to s1 do     //匈牙利
    if cx[i]=- then
    begin
      fillchar(v,sizeof(v),false);
      ans:=ans+find(i);
    end;
  writeln(ans);
end.

一定要注意问题建模的灵活运用;

poj3041,poj2226的更多相关文章

  1. POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K       Description As we all know, machine ...

  2. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  3. Pyhton开源框架(加强版)

    info:Djangourl:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC)风格的 ...

  4. MPlayer

    名称   mplayer − 电影播放器 mencoder − 电影编解码器 概要   mplayer [选项] [文件|URL|播放列表|−] mplayer [选项] 文件1 [指定选项] [文件 ...

  5. python 爬取腾讯微博并生成词云

    本文以延参法师的腾讯微博为例进行爬取并分析 ,话不多说 直接附上源代码.其中有比较详细的注释. 需要用到的包有 BeautifulSoup WordCloud jieba # coding:utf-8 ...

  6. 面经 cisco

    1. 优先级反转问题及解决方法 (1)什么是优先级反转 简单从字面上来说,就是低优先级的任务先于高优先级的任务执行了,优先级搞反了.那在什么情况下会生这种情况呢? 假设三个任务准备执行,A,B,C,优 ...

  7. linux驱动(续)

    网络通信 --> IO多路复用之select.poll.epoll详解 IO多路复用之select.poll.epoll详解      目前支持I/O多路复用的系统调用有 select,psel ...

  8. HttpServletRequest对象(一)

    javaweb学习总结(十)——HttpServletRequest对象(一) 一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HT ...

  9. 【poj2226】 Muddy Fields

    http://poj.org/problem?id=2226 (题目链接) 题意 给出一个只包含‘.’和‘*’的矩阵,用任意长度的宽为1的木板覆盖所有的‘*’而不覆盖‘.’,木板必须跟矩形的长或宽平行 ...

随机推荐

  1. php提取淘宝URL中ID的代码

    一段可以提取淘宝URL中ID的PHP代码. 例如: <?php $taobao = 'taobao.com'; $tmall = 'tmall.com'; $guojitmall = 'tmal ...

  2. cadence 封装制作小结

    assembly :是装配层,就是元器件的实际大小,用来产生元器件的装配图.也可以使用此层进行布局:外框尺寸应该为元件除焊盘外的部分 该区域可比silkscreen小10mil,线宽不用设置,矩形即可 ...

  3. You have new mail in /var/spool/mail/root 烦不烦你?

    http://blog.csdn.net/yx_l128125/article/details/7425182

  4. css tricks

    http://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/ http://css-tricks.com/brows ...

  5. tableView的基本使用(改良版)

    @interface ViewController ()<UITableViewDataSource, UITableViewDelegate> { int i;//用来计算接受通知的次数 ...

  6. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

  7. hdu 4192

    dfs全排列  加  模拟计算 #include <iostream> #include <cstdio> #include <cstdlib> #include ...

  8. 20130729--Samba的学习

    (一).基本概念 samba是一个能让你的Unix计算机和其它MS Windows计算机相互共享资源的软件. samba提供有关资源共享的三个功能,包括:smbd,执行它可以使Unix能够共享资源给其 ...

  9. C: 数组形参

    知识这个东西,真是知道的越多就不知道的越多,C/C++这塘水得多深啊,哈哈.看下面3个片段:<一> 1 void fun(char a[100]) { 2         fprintf( ...

  10. 【leetcode】Trapping Rain Water(hard)

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...