Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7329   Accepted: 3635

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

Source

 

提示:别被图片的圈圈误导了,看清楚题目,'*'是城市,'o'是空地,椭圆的天线覆盖范围要覆盖的是城市'*',而不是覆盖空地

题目大意:

一个矩形中,有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<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int map[maxn][maxn];
char c[maxn][maxn];
bool vis[maxn];
int link[maxn],g[maxn][maxn];
int tx,ty;
int next[][]={,,,,,-,-,};
bool find(int u){
for(int i=;i<=ty;i++){
if(!vis[i]&&g[u][i]){
vis[i]=true;
if(link[i]==-||find(link[i])){
link[i]=u;
return true;
}
} }
return false;
}
int solve(){
int sum=;
memset(link,-,sizeof(link));
for(int i=;i<=tx;i++){
memset(vis,false,sizeof(vis));
if(find(i))
sum++;
}
return sum;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(g,,sizeof(g));
memset(c,,sizeof(c));
memset(map,,sizeof(map));
int m,n;
cin>>m>>n;
int ans=;
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
cin>>c[i][j];
if(c[i][j]=='*'){
map[i][j]=++ans;
}
}
}
tx=ty=ans;
//printf("%d %d\n",tx,ty);
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
if(map[i][j]){
for(int k=;k<;k++){
int xx=i+next[k][];
int yy=j+next[k][];
if(xx<||xx>m||yy<||yy>n)
continue;
if(map[xx][yy])
g[map[i][j]][map[xx][yy]]=;
}
}
}
}
printf("%d\n",ans-solve()/); }
return ;
}

poj 3020 最短路径覆盖 Antenna Placement的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Antenna Placement POJ - 3020 (最小边集覆盖)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10699   Accepted: 526 ...

  7. POJ 3020 Antenna Placement 【最小边覆盖】

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

  8. 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement

    题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...

  9. POJ 3020 Antenna Placement 最大匹配

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 3182 ...

随机推荐

  1. SequoiaDB 系列源码分析调整

    犹豫我经验尚不够丰富,有大牛跟我说,以我这样定下的结构来分析源码,学习效果不太好. 应该先从程序的进程入口函数开始,慢慢的跟流程来分析.先通过系统的启动.退出来分析所用到的技术,像进程模型,线程模型等 ...

  2. Javascript基础系列之(一)JavaScript语法

    javascript的语法 1.区分大小写 javascript中,变量.函数.运算符都区分大小写. 2.弱类型变量 定义变量只用 "var"关键字 var age = 25; v ...

  3. c#批量插入示例

    var sql = @"Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20131029153010;I ...

  4. wordpress中如何禁止或者屏蔽更新提示

    WordPress禁止,插件更新,主题更新,wordpress本身更新提示的方法 禁止wp更新 : open file "wordpress\wp-includes\update.php&q ...

  5. ie6下使用js替换img标签src属性图片不显示的错误

    首先,我必须再次强调一下,F-U-C-K I-E! 其次,简单阐述一下这个bug的出现的情况.页面中有个<a href=”javascript:void(0)” onclick=”swapImg ...

  6. Android Studio能干什么

    建立系统工具包可以用来生成,测试,运行您的应用程序和软件包.构建系统是独立于Android的工作室,所以你可以调用它的Android的工作室或从命令行.在你写你的应用程序,你可以使用编译系统的特点: ...

  7. Cocos2d-X3.0 刨根问底(二)----- 从HelloWorld开始

    小鱼习惯直接从代码实例来学习一套成型的引擎库. 运行cpp-empty-test 一个典型的HelloWorld程序翻看代码结构 看到了 main.h与main.cpp文件就从这里开始 #ifndef ...

  8. 界面原型Axure

    页面原型工具 Axure 超实用页面原型工具.好的页面原型是项目组成员顺利沟通的一个非常重要因素,Axure能快速制作页面原型,还能界面手动式加上事件,链接跳转,弹出层等等一切HTML开发中常用功能, ...

  9. [前端]前端面试题第二波~[http/tcp/网络篇]

    目录: Cookie 是否会被覆盖,localStorage是否会被覆盖? 如何保持登陆状态? Ajax原生 Jsonp的原理.怎么去读取一个script里面的数据. 如果页面初始载入的时候把ajax ...

  10. Eclipse在线安装ADT插件

    要想使用Eclipse开发Android应用,首先要安装一个ADT插件,在此记录一下在Eclipse中采用在线安装的方式ADT插件,我使用的Eclipse版本是:eclipse-jee-luna-SR ...