poj 3020 Antenna Placement

Antenna Placement
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5803 Accepted: 2901

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

 

转载:優YoU  http://user.qzone.qq.com/289065406/blog/1299322779

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

 

题目大意:

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


解题思路:

思前想后,依稀可以认为是一道求二分图的最小路径覆盖问题

(注意不是最小点覆盖)

 

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

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

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

 

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

 

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

 

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

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

构造方法如下:

例如输入:

*oo

***

O*o

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

100

234

050

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

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

因此就能够得到边集:

e12  e21     e32     e43    e53

     e23     e34

             e35

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

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

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

 

接下来的没完全转载,我就是直接构图,遍历一遍n*m的图,利用其上下左右的关系得出边(具体看代码构图部分)。思路也是看了别人的才想到,有点木了- -

 

 1 //812K    16MS    C++    1657B    2013-11-09 16:41:40
 2 #include<stdio.h>
 3 #include<string.h>
 4 char map[45][15];
 5 int nmap[45][15]; 
 6 int g[405][405]; //最多有 40*10 个顶点  
 7 int match[405];
 8 int vis[405];
 9 int n,m,sum; //sum记录总定点数 
10 void build() //建图 
11 {
12     memset(g,0,sizeof(g));
13     memset(nmap,0,sizeof(nmap)); 
14     for(int i=1;i<=n;i++)
15         for(int j=1;j<=m;j++)
16             if(map[i-1][j-1]=='*'){
17                 sum++;
18                 nmap[i][j]=sum;
19             }
20     for(int i=1;i<=n;i++)
21         for(int j=1;j<=m;j++){
22             if(nmap[i][j]){
23                 if(i+1<=n)  //注意边界值 
24                     g[nmap[i][j]][nmap[i+1][j]]=g[nmap[i+1][j]][nmap[i][j]]=1; //无向图 
25                 if(i-1>=1)
26                     g[nmap[i][j]][nmap[i-1][j]]=g[nmap[i-1][j]][nmap[i][j]]=1;
27                 if(j+1<=m)
28                     g[nmap[i][j]][nmap[i][j+1]]=g[nmap[i][j+1]][nmap[i][j]]=1;
29                 if(j-1>=1)
30                     g[nmap[i][j]][nmap[i][j-1]]=g[nmap[i][j-1]][nmap[i][j]]=1;
31             }
32         }
33 }
34 int dfs(int x)
35 {
36     for(int i=1;i<=sum;i++){
37         if(!vis[i] && g[x][i]){
38             vis[i]=1;
39             if(match[i]==-1 || dfs(match[i])){
40                 match[i]=x;
41                 return 1;
42             }
43         }
44     }
45     return 0;        
46 }
47 void hungary()
48 {
49     memset(match,-1,sizeof(match));
50     int ret=0;
51     for(int i=1;i<=sum;i++){
52         memset(vis,0,sizeof(vis));
53         ret+=dfs(i);
54     }
55     printf("%d\n",sum-ret/2); //无向图 
56 }
57 int main(void)
58 {
59     int t;
60     scanf("%d",&t);
61     while(t--)
62     {
63         scanf("%d%d%*c",&n,&m);
64         for(int i=0;i<n;i++) 
65             scanf("%s",map[i]);
66         sum=0;
67         build();
68         hungary();
69     }
70     return 0;
71 }

转载于:https://www.cnblogs.com/GO-NO-1/articles/3415806.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值