Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7788   Accepted: 3880

Description

The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them. 
 
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?

Input

On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space.

Output

For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

Sample Input

2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*

Sample Output

17
5 http://blog.csdn.net/lyy289065406/article/details/6647040

题目大意:

一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,若放置一个基站,那么它至多可以覆盖相邻的两个城市。
问至少放置多少个基站才能使得所有的城市都覆盖无线?

解题思路:

思前想后,依稀可以认为是一道求二分图的最小路径覆盖问题(我就想求点覆盖了,但是如果想想如果是独立的点的话,就会排除点覆盖,因为点覆盖的是连线)

(注意不是最小点覆盖)

那么接下来需要确认的是,

究竟是求 有向二分图的最小路覆盖,还是求 无向二分图的最小路覆盖

因为有向和无向是截然不同的计算方法。

要确认是构造有向图,还是构造无向图,那么就需要先根据题意,看看构造二分图时所使用的方式,更适合构造哪一种二分图。

然后就进入了本题难点:如何构造二分图

首先要明确的是,输入的一堆“圈圈星星”可以看做是一张大地图,地图上有所有城市的坐标,但是这里有一个误区:不能简单地把城市的两个x、y坐标作为准备构造的二分图的两个顶点集。

城市才是要构造的二分图的顶点!

构造方法如下:

例如输入:

*oo

***

O*o

时,可以抽象为一个数字地图:

100

234

050

数字就是根据输入的城市次序作为该城市的编号,0代表该位置没有城市。

然后根据题目的“范围”规则,从第一个城市开始,以自身作为中心城市,向四个方向的城市进行连线(覆盖)

因此就能够得到边集:

e12  e21     e32     e43    e53

e23     e34

e35

可以看到,这些边都是有向边,但是每一条边都有与其对应的一条相反边。

任意两个城市(顶点)之间的边是成对出现的

那么我们就可以确定下来,应该 构造无向二分图(其实无向=双向)

因为若要构造有向的二分图时,需要判断已出现的边,是很麻烦的工作

为了把有向图G构造为无向二分图,这里需要引入一个新名词“拆点”

其实就是把原有向图G的每一个顶点都”拆分(我认为复制更准确)”为2个点,分别属于所要构造的二分图的两个顶点集

例如在刚才的例子中抽出一条有向边e12举例说明:

复制顶点1和顶点2,使得1,2∈V1;  1’,2’∈V2 ,不难发现|V1|=|V2|

根据边e12和e21,得到无向二分图:

那么同理就可以得到刚才的例子的 无向二分图为:

再继而通过无向二分图,以V1的元素作为row,V2的元素作为col,构造 可达矩阵 存储到计算机

1’  2’  3’  4’  5’

1  F  T   F   F   F

2  T  F   T   F   F

3  F  T   F   T   T

4  F  F   T   F   F

5  F  F   T   F   F

接下来就是要求这个 无向二分图的最小路径覆盖 了

利用公式:

无向二分图的最小路径覆盖 = 顶点数 – 最大二分匹配数/2

顶点数:就是用于构造无向二分图的城市数,即进行“拆点”操作前的顶点数量

最大二分匹配书之所以要除以2,是因为进行了“拆点”擦奥做做使得匹配总数多了一倍,因此除以2得到原图的真正的匹配数

最后剩下的问题就是求最大二分匹配数了,用匈牙利算法,这就不多说了,参考POJ3041的做法,基本一摸一样。

从这道题得出了一个结论:

当二分图的两个顶点子集基数相等时,该二分图所有顶点的匹配数 等于 任意一个顶点子集匹配数的2倍

其实匈牙利算法解题是极为简单的,但是图论的难并不是难在解答,而是建图的过程,也难怪会有牛曰:用匈牙利算法,建图是痛苦的,最后是快乐的。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = ;
int g[MAX][MAX],s[MAX*MAX][MAX*MAX];
int vis[],link[];
char ch;
int t,m,n,k;
int dfs(int x)
{
for(int i = ; i < k; i++)
{
if(vis[i] == && s[x][i])
{
vis[i] = ;
if(link[i] == || dfs(link[i]))
{
link[i] = x;
return true;
}
}
}
return false;
}
int main()
{
scanf("%d",&t);
while(t--)
{
k = ;
scanf("%d%d",&n,&m);
memset(g,,sizeof(g));
memset(s,,sizeof(s));
memset(link,,sizeof(link));
getchar();
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
scanf("%c",&ch);
if(ch == '*')
g[i][j] = k++;
}
getchar();
}
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
if(g[i][j])
{
if(g[i - ][j])
s[ g[i][j] ][ g[i - ][j] ] = ;
if(g[i + ][j])
s[ g[i][j] ][ g[i + ][j] ] = ;
if(g[i][j + ])
s[ g[i][j] ][ g[i][j + ] ] = ;
if(g[i][j - ])
s[ g[i][j] ][ g[i][j - ] ] = ;
} }
}
int ans = ;
for(int i = ; i < k; i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",k - ans / - );
} return ;
}

POJ3020Antenna Placement(最小路径覆盖+重在构图)的更多相关文章

  1. poj 3020 Antenna Placement (最小路径覆盖)

    链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...

  2. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  3. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  4. POJ3020 Antenna Placement(二分图最小路径覆盖)

    The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...

  5. POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】

    Antenna Placement Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  6. POJ:3020-Antenna Placement(二分图的最小路径覆盖)

    原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...

  7. POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6334   Accepted: 3125 ...

  8. poj 3020 Antenna Placement (最小路径覆盖)

    二分图题目 当时看到网上有人的博客写着最小边覆盖,也有人写最小路径覆盖,我就有点方了,斌哥(kuangbin)的博客上只给了代码,没有解释,但是现在我还是明白了,这是个最小路径覆盖(因为我现在还不知道 ...

  9. Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖

    题意:图没什么用  给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖       最小路径覆盖=|G|-最大匹配数 ...

随机推荐

  1. 10Spring_AOP编程(传统编程)

    注意我写这篇文章的思路,要想做切面编程,包含两个部分,通知和切点,通知是你要做哪些增强,切点是指你要拦截哪些方法.先介绍通知的定义再去介绍切点的定义.这篇文章我取名叫做Spring_AOP编程(传统编 ...

  2. 13Spring_AOP编程(AspectJ)_后置通知

    后置通知和前置通知差不多.最大的特点是因为后置通知是运行在目标方法之后的,所以他可以拿到目标方法的运行的结果. 给出案例: 案例结构图:

  3. RDLC报表系列--------行分组报表

    报表分组开发步骤: 先看总体效果:如图 下面就做个看看... 1.先将数据处理成如下结构 如图 2.创建数据集DataSet.xsd,创建表->右键选择添加数据表->添加行(ctrl+L ...

  4. ruby on rails gem install pg时无法安装

    gem install pg -v '0.18.2' Building native extensions. This could take a while... ERROR: Error insta ...

  5. HTML基础 - <base>标签的使用

    标签对于不是很熟悉前端的人应该还算是个生面孔吧,粗略讲讲标签的用法. 将相对路径变成绝对路径 这个对于需要借(chao)鉴(xi)别人网页的时候特别有用~ 批量设置target=_blank 当需要对 ...

  6. ntp时间同步服务器配置

    ntp同步的两种方式:1.使用ntpdate命令直接同步 2.使用NTPD服务平滑同步直接同步方式的缺陷:会导致已经做的定时任务再做一遍.平滑同步每次同步时间的偏移量不会太陡,根据偏移量,均方差等值每 ...

  7. Eclipse系列:如何断点调试web项目

    一直不知道如何在Eclipse中断点调试跟踪问题,今天试了一把,大致的步骤如下: 1)事先在需要断点跟踪的代码行左侧空白处双击处设置断点: 2)在工程列表中选中要调试的工程,然后点击Debug on ...

  8. ios 解析html

    xml,json都有大量的库来解析,我们如何解析html呢? TFHpple是一个小型的封装,可以用来解析html,它是对libxml的封装,语法是xpath.今天我看到一个直接用libxml来解析h ...

  9. 第二十课:js中如何操作元素的属性系统

    本章的内容有点复杂,我将用简单的方式来介绍重要的东西,不重要的东西,这里就不讲了,讲了也毛用. 通常我们把对象的非函数成员叫做属性.对元素节点来说,其属性大题分为两大类,固有属性和自定义属性.固有属性 ...

  10. angular实例教程(用来熟悉指令和过滤器的编写)

    angular的插件太少了,  所以很多指令和过滤器都要自己写,  所以对指令传进来的参数, 以及angular编译的流程更加熟悉才行写出好的插件, 有些简单的指令是参考angularUI里面, 作为 ...