传送门:http://poj.org/problem?id=3020

Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11098   Accepted: 5464

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

题意概括:

给一个高为 H 宽为 W 的图案, “  *  ” 表示城市,每个城市可以覆盖 它 上下左右相邻的 其中一个城市,问最好需要多少城市才能把所有城市覆盖。

解题思路:

按照城市编号,然后拆点建图,相邻两个城市可以覆盖的就连边,跑一遍最小边覆盖。

AC code:

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXH = ;
const int MAXW = ;
const int MAXN = ;
struct Edge
{
int v, nxt;
}edge[MAXN*MAXN];
int head[MAXN], cnt;
int linker[MAXN];
bool used[MAXN];
char str[MAXH][MAXW];
int a[MAXH][MAXW];
int sum;
int H, W; void init()
{
memset(head, -, sizeof(head));
memset(linker, -, sizeof(linker));
memset(a, , sizeof(a));
cnt = ;
sum = ;
} void add(int from, int to)
{
edge[cnt].v = to;
edge[cnt].nxt = head[from];
head[from] = cnt++;
} bool Find(int x)
{
int v;
for(int i = head[x]; i != -; i = edge[i].nxt){
v = edge[i].v;
if(!used[v]){
used[v] = true;
if(linker[v] == - || Find(linker[v])){
linker[v] = x;
return true;
}
}
}
return false;
} int main()
{
int T_case;
scanf("%d", &T_case);
while(T_case--){
init();
scanf("%d%d", &H, &W);
for(int i = ; i < H; i++){
scanf("%s", &str[i]);
for(int j = ; j < W; j++)
if(str[i][j]=='*') a[i][j] = ++sum;
} for(int i = ; i < H; i++){
for(int j = ; j < W; j++){
if(a[i][j]){
if(i > && a[i-][j]) add(a[i][j], a[i-][j]);
if(i < H- && a[i+][j]) add(a[i][j], a[i+][j]);
if(j > && a[i][j-]) add(a[i][j], a[i][j-]);
if(j < W- && a[i][j+]) add(a[i][j], a[i][j+]);
}
}
} int ans = ;
for(int i = ; i <= sum; i++){
memset(used, , sizeof(used));
if(Find(i)) ans++;
}
printf("%d\n", sum-ans/);
}
return ;
}

POJ 3020 Antenna Placement 【最小边覆盖】的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. POJ 3020 Antenna Placement(二分图 匈牙利算法)

    题目网址:  http://poj.org/problem?id=3020 题意: 用椭圆形去覆盖给出所有环(即图上的小圆点),有两种类型的椭圆形,左右朝向和上下朝向的,一个椭圆形最多可以覆盖相邻的两 ...

  8. POJ 3020 Antenna Placement 最大匹配

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

  9. poj 3020 Antenna Placement(二分无向图 匈牙利)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6438   Accepted: 3176 ...

随机推荐

  1. spark第四篇:Running Spark on YARN

    确保HADOOP_CONF_DIR或者YARN_CONF_DIR指向hadoop集群配置文件目录.这些配置用来写数据到hdfs以及连接yarn ResourceManager.(在$SPARK_HOM ...

  2. 理解fig,ax = plt.subplots()

    fig = plt.figure() ax = fig.add_subplot(1,1,1) fig, ax = plt.subplots(1,3),其中参数1和3分别代表子图的行数和列数,一共有 1 ...

  3. oracle 基础知识(十)----exp/imp--->>>>>expdp/impdp

    一,简介 存活下来的远古级别的导入导出软件exp/imp  ,软件多数使用于oracle 9i 之前 到了10g以后基本全面被数据库泵(Data Pump)取代,即expdp/impdp.本文会分别介 ...

  4. 基于memcache的缓存机制的6个指令

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...

  5. Android应用程序组件之间的通信Intent和IntentFilter

    Android应用程序的基本组件,这些基本组建除了Content Provider之外,几乎全部都是依靠Intent对象来激活和通信的. 下面介绍Intent类,并通过例子来说明Intent一般用法 ...

  6. [Scala] Pattern Matching(模式匹配)

    Scala中的match, 比起以往使用的switch-case有著更強大的功能, 1. 傳統方法 def toYesOrNo(choice: Int): String = choice match ...

  7. C语言中extern的用法--转

    http://blog.sina.com.cn/s/blog_52deb9d50100ml6y.html 在C语言中,修饰符extern用在变量或者函数的声明前,用来说明“此变量/函数是在别处定义的, ...

  8. PLC通信网络

    PLC通信网络的分层 PLC通信网络大致可分为3层,管理层,单元层以及现场执行(AS-I)层.如下图所示. 在PLC通信网络的三层架构中,管理层,通信方式包括MPI,工业以太网(Profinet)以及 ...

  9. 关于EF执行返回表的存储过程

    1.关于EF执行返回表的存储过程 不知道为什么EF生成的存储过程方法会报错,以下方法可以使用,call是MySQL执行存储过程的命令 [HttpGet] public HttpResponseMess ...

  10. C#中TransactionScope的使用方法和原理(摘)

    出自51CTO博客:http://cnn237111.blog.51cto.com/2359144/1271600 在.net 1.1的时代,还没有TransactionScope类,因此很多关于事务 ...