传送门: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. 安装clouderamaner时出现Failed to detect distribution错误(在ubuntu14.04版本里)

    不多说,直接上干货! 在安装过程中,本来我的ubuntu系统都是14.04的.  问题详情 问题查看 解决办法 然后,再次执行安装即可. 欢迎大家,加入我的微信公众号:大数据躺过的坑        人 ...

  2. 转-------基于R-CNN的物体检测

    基于R-CNN的物体检测 原文地址:http://blog.csdn.net/hjimce/article/details/50187029 作者:hjimce 一.相关理论 本篇博文主要讲解2014 ...

  3. [转]批处理for命令使用指南

    摘要:本文由浅入深,为大家专门讲解for的用法,希望大家喜欢. 首先应该明确的是,for不是一个简单的命令,它的用法比较复杂,它还可以带四个参数(/L /D /R /F),其中:/L和/F参数是最经常 ...

  4. 九度oj题目1518:反转链表

    题目1518:反转链表 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2567 解决:948 题目描述: 输入一个链表,反转链表后,输出链表的所有元素.(hint : 请务必使用链表) ...

  5. ArrayList  集合

    ArrayList       集合:很多数据的一个集合       数组:长度不可变.类型单一 集合的好处:长度可以任意改变  类型随便 集合长度都的问题   很多数据的集合数组类型不可变 长度单一 ...

  6. java实例初始化块

    实例初始化程序块用于初始化实例数据成员. 它在每次创建类的对象时运行.实例变量的初始化可以是直接的,但是可以在初始化实例初始化块中的实例变量时执行额外的操作. 什么是实例初始化块的使用,我们可以直接分 ...

  7. Scrapy框架之日志等级和请求传参

    一.Scrapy的日志等级 在使用scrapy crawl spiderFileName运行程序时,在终端里打印输出的就是scrapy的日志信息. 1.日志等级(信息种类) ERROR:错误 WARN ...

  8. html5 嵌入元素 img map areaiframe embed meter object meter

    <img src="路径">            src 路径可以是img.jpg 也可以是 绝对和相对路径+img.jpg <img src="路径 ...

  9. .NET开源工作流RoadFlow-流程运行-菜单配置

    经过流程设计和表单设计后,一个流程就设置完成了,下面说说怎么让设计好的流程运行起来吧. 流程和表单设计完成发布后都在应用程序库里,我们只要将流程在角色应用中配置给相应的用户即可让流程选择了. 在系统管 ...

  10. JSP初学者5

    JSP中include指令和include动作的区别 include指令是编译阶段的指令,即include所包含的文件的内容是编译的时候插入到JSP文件中,  JSP引擎在判断JSP页面未被修改,否则 ...