题目链接:https://vjudge.net/problem/POJ-3020

Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9995   Accepted: 4939

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

题解:

1.首先为每个“*”编号。然后对于当前的“*”, 如果它的上面有“*”,则在这两个“*”之间连一条边,同理其他三个方向。

2.利用匈牙利算法求出最大匹配数cnt,即表明最多有cnt个“*”可以与其他“*”共用,所以最少需要N-cnt个。

3.其实此题求的就是最小边覆盖:最小边覆盖 = 结点数 - 最大匹配数

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9+;
const int MAXN = +; int N;
char a[MAXN][MAXN];
int M[MAXN][MAXN], id[MAXN][MAXN], link[MAXN];
bool vis[MAXN]; bool dfs(int u)
{
for(int i = ; i<=N; i++)
if(M[u][i] && !vis[i])
{
vis[i] = true;
if(link[i]==- || dfs(link[i]))
{
link[i] = u;
return true;
}
}
return false;
} int hungary()
{
int ret = ;
memset(link, -, sizeof(link));
for(int i = ; i<=N; i++)
{
memset(vis, , sizeof(vis));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
int T, n, m;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
N = ;
memset(id, -, sizeof(id));
for(int i = ; i<=n; i++)
{
scanf("%s", a[i]+);
for(int j = ; j<=m; j++)
if(a[i][j]=='*')
id[i][j] = ++N;
} memset(M, false, sizeof(M));
for(int i = ; i<=n; i++)
for(int j = ; j<=m; j++)
{
if(id[i][j]==-) continue;
if(j!= && id[i][j-]!=-) M[id[i][j]][id[i][j-]] = true;
if(j!=m && id[i][j+]!=-) M[id[i][j]][id[i][j+]] = true;
if(i!= && id[i-][j]!=-) M[id[i][j]][id[i-][j]] = true;
if(i!=n && id[i+][j]!=-) M[id[i][j]][id[i+][j]] = true;
} int cnt = hungary()/;
printf("%d\n", N-cnt);
}
}

POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖的更多相关文章

  1. PKU 3020 Antenna Placement(拆点+最小边覆盖)(最大匹配)

    题目大意:原题链接 一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,若放置一个基站,那么它至多可以覆盖相邻的两个城市.问至少放置多少个基站才能使得所有的城市都覆盖无线? 提示:看清楚题目,' ...

  2. poj3020 Antenna Placement 匈牙利算法求最小覆盖=最大匹配数(自身对应自身情况下要对半) 小圈圈圈点

    /** 题目:poj3020 Antenna Placement 链接:http://poj.org/problem?id=3020 题意: 给一个由'*'或者'o'组成的n*m大小的图,你可以用一个 ...

  3. POJ3020——Antenna Placement(二分图的最大匹配)

    Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...

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

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

  5. POJ3020 Antenna Placement

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9586   Accepted: 4736 ...

  6. POJ 3020 Antenna Placement 最大匹配

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

  7. POJ-3020 Antenna Placement---二分图匹配&最小路径覆盖&建图

    题目链接: https://vjudge.net/problem/POJ-3020 题目大意: 一个n*m的方阵 一个雷达可覆盖两个*,一个*可与四周的一个*被覆盖,一个*可被多个雷达覆盖问至少需要多 ...

  8. hdu4185+poj3020(最大匹配+最小边覆盖)

    传送门:hdu4185 Oil Skimming 题意:n*n的方格里有字符*和#,只能在字符#上放1*2的板子且不能相交,求最多能放多少个. 分析:直接给#字符编号,然后相邻的可以匹配,建边后无向图 ...

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

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

随机推荐

  1. DOS使用笔记

    DOS下cd命令: cd .. 上一级目录: g: 指定当期目录到G盘,而cd g:是没有效果的: 如图: 在安装Windows服务的过程中,如果installutil为64位版本,那么编译生成项目的 ...

  2. ArrayList集合的增删改查方法

    新建一个myArrayList项目 在myArrayList项目下创建一个包 包中创建一个ArrayListDemo2.java文件 ArrayListDemo2.java import java.u ...

  3. 解决safari里面淘宝京东页面无法打开以及打开后乱码的问题!

    sqlite3 ~/Library/Keychains/*/ocspcache.sqlite3 'DELETE FROM responses WHERE responderURI LIKE " ...

  4. 大数据学习——安装zooleeper

    1 alt+p,上传zookeeper-3.4.5.tar.gz 2 解压安装包 ,安装在apps目录下 tar -zxvf zookeeper-3.4.5.tar.gz -C apps 3 删除zo ...

  5. idea web项目启动失败的情况---webapp文件夹路径不对,应如图位置

  6. PHP建立和删除目录

    <?php/*linux中的文件权限filedir 用户 组 其它 rwx rwx rwx 读写执行 6 4 6 读写 读 读写 7 7 7 rw_ r__ rw_ r__ _w_ ___ r ...

  7. eclipse pom.xml 报错org.apache.maven.plugin.war.WarMojo的解决办法

    如题,maven项目eclipse提示pom.ml有错,提示信息就是org.apache.maven.plugin.war.WarMojo. 然后执行 maven install 出现如下错误提示 [ ...

  8. mysql获取行号的方法

    1.不排序 语句: ) ) ) b,bigquestion 结果:  2.排序的 语句 ) ) ) b,bigquestion order by bigquestion.bigQuestionSequ ...

  9. Swift--方法(函数)

    方法是执行特殊任务的自包含代码块.你可以给方法名字来表示它的功能,而且在需要的时候调用这个名字的方法来执行它的任务. Swift方法的语法表达很灵活,从类似c的没有参数名的方法到oc复杂的带有名字和参 ...

  10. webstorm初始化

    1.皮肤设置,重启后Terminal皮肤生效 2.排除目录 2.1全局排除 2.2局部排除 选中文件夹 右击Make Directroy As 选择 Excluded 3.代码自定义 3.1 cons ...