传送门: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. C语言两种方式实现矩阵的转置

    #include"stdio.h" typedef struct{ int i,j; int v; }Triple; typedef struct{ Triple date[]; ...

  2. Oracle RAC集群搭建(五)--oracle部署

    01,配置好环境 节点01--node1 ORACLE_BASE=/oracle/app/oracle ORACLE_HOME=$ORACLE_BASE/product//db_1 ORACLE_SI ...

  3. mysql 数据存储引擎区别

    一,存储类型 二 , MyISAM默认存储引擎 MyISAM 管理非事务表.是ISAM 的扩展格式.除了提供ISAM里所没有的索引的字段管理等的大量功能.MyISAM 还使用一种表格锁定的机制.来优化 ...

  4. hibernate离线查询DetachedCriteria清除上次的查询条件

    1 原例概述 别名重复问题之后,我们还需要解决的问题就是: 如何清除hibernate的上次查询条件,如果不清除,将会导致上次的查询条件和下次的查询条件合并到了一起. 上次的查询条件和本次的查询条件合 ...

  5. elasticSearch请求流程图

  6. Pygame 加载音频

    Python Learning:Pygame 加载音频 Python 中自带的 winsound 模块 winsound 模块中 Beep 方法可以调用系统的蜂鸣器,接受一个为 frequency 的 ...

  7. js 常用事件句柄总结

    HTML 4.0 的新特性之一是有能力使 HTML 事件触发浏览器中的动作(action),比如当用户点击某个 HTML 元素时启动一段 JavaScript.下面是一个属性列表,这些属性可插入 HT ...

  8. MVC 下拉框获取值和赋值(多选)

    1.视图 <div class="form-group"> @Html.LabelFor(m => m.Positions, new { @class = &qu ...

  9. 【学习笔记】HTML基础:列表、表格与媒体元素

    一.列表是信息资源的一种展现形式,它可以使信息结构化和条理化,并以列表的样式显示出来,以便浏览者能够快速的获取相应的信息. 1.无需列表 <ul> <li>第一项</li ...

  10. Android-事件处理机制(待补充)

    http://www.cnblogs.com/plokmju/archive/2013/03/13/2955175.html Android有两条事件处理机制 基于监听的事件处理 基于回调的事件处理 ...