Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10699   Accepted: 5265

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

 
这道题直接用HDU - 4185的代码改一下就好。。。。
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
int dx[maxn], dy[maxn], cx[maxn], cy[maxn], used[maxn];
int nx, ny, dis, n;
char str[][];
int gra[][];
vector<int> G[];
int dir[][] = {{,},{-,},{,},{,-}};
int bfs()
{
queue<int> Q;
dis = INF;
mem(dx, -);
mem(dy, -);
for(int i=; i<=nx; i++)
{
if(cx[i] == -)
{
Q.push(i);
dx[i] = ;
}
}
while(!Q.empty())
{
int u = Q.front(); Q.pop();
if(dx[u] > dis) break;
for(int v=; v<G[u].size(); v++)
{
int i=G[u][v];
if(dy[i] == -)
{
dy[i] = dx[u] + ;
if(cy[i] == -) dis = dy[i];
else
{
dx[cy[i]] = dy[i] + ;
Q.push(cy[i]);
}
}
}
}
return dis != INF;
} int dfs(int u)
{
for(int v=; v<G[u].size(); v++)
{
int i = G[u][v];
if(!used[i] && dy[i] == dx[u] + )
{
used[i] = ;
if(cy[i] != - && dis == dy[i]) continue;
if(cy[i] == - || dfs(cy[i]))
{
cy[i] = u;
cx[u] = i;
return ;
}
}
}
return ;
} int hk()
{
int res = ;
mem(cx, -);
mem(cy, -);
while(bfs())
{
mem(used, );
for(int i=; i<=nx; i++)
if(cx[i] == - && dfs(i))
res++;
}
return res;
} int main()
{
int T, kase = ;
cin>> T;
while(T--)
{
mem(gra, );
int ans = ;
for(int i=; i<maxn; i++) G[i].clear();
cin>> n;
for(int i=; i<n; i++)
{
cin>> str[i];
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
gra[i][j] = ++ans; } }
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(str[i][j] == '#')
for(int k=; k<; k++)
{
int nx = i + dir[k][];
int ny = j + dir[k][];
if(str[nx][ny] == '#' && nx >= && ny >= && nx < n && ny < n)
G[gra[i][j]].push_back(gra[nx][ny]), G[gra[nx][ny]].push_back(gra[i][j]);
}
}
}
nx = ny = ans;
printf("Case %d: %d\n",++kase, hk()/);
} return ;
}

Antenna Placement POJ - 3020 (最小边集覆盖)的更多相关文章

  1. Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖

    题意:图没什么用  给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖       最小路径覆盖=|G|-最大匹配数 ...

  2. (匹配 二维建图) Antenna Placement --POJ --3020

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

  3. Antenna Placement poj 3020

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12104   Accepted: 595 ...

  4. Antenna Placement poj 3020(匹配)

    http://poj.org/problem?id=3020 题意:给定一个n*m的矩阵,'*'代表城市,现在想要用1*2的矩阵将所有的城市覆盖,问最少需要多少个矩阵? 分析:先为每个城市进行标号,再 ...

  5. (匹配)Antenna Placement --POJ --3020

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

  6. POJ 3216 最小路径覆盖+floyd

    Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6646   Accepted: 178 ...

  7. poj 1548(最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...

  8. POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖

    题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K ...

  9. poj 3216 (最小路径覆盖)

    题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...

随机推荐

  1. 架构图+kubernetes 问题理解 -- kube-pproxy - endpoint

    1.详述kube-proxy原理,一个请求是如何经过层层转发落到某个pod上的整个过程.请求可能来自pod也可能来自外部. 1.1kube-proxy为集群提供service功能,相同功能的pods对 ...

  2. Swift10大开源项目记录

    Alamofire : Swift编写的HTTP网络库,用于异步网络通信. Surge: Surge基于Accelerate框架开发,用于执行矩阵数学.数字信号处理以及图像处理等方面. SwiftyJ ...

  3. ASP.NET Core MVC中的IActionFilter.OnActionExecuting方法,可以获取Controller的Action方法参数值

    用过ASP.NET Core MVC中IActionFilter拦截器的开发人员,都知道这是一个非常强大的MVC拦截器.最近才发现IActionFilter的OnActionExecuting方法,甚 ...

  4. Python3入门(四)——Python函数

    一.概述 python和其他高级语言一样,支持函数 注意和scala不一样,结果必须使用return,否则默认return None!这和scala最后一个值作为返回是不一样的! 二.函数调用 和其他 ...

  5. WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法。

    原文:WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/articl ...

  6. vim打开多窗口、多文件之间的切换

    打开多个文件: 一.vim还没有启动的时候: 1.在终端里输入  vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :e file 可以再打开一 ...

  7. 快速定位iOS线上BUG在哪个控制器崩溃

    快速定位iOS线上App崩溃在哪个控制器里面,需要和后台配合使用 下载本SDK并手动添加到项目里 新建所有的页面都继承于YZViewController 在AppDelegate的didFinishL ...

  8. Error:Could not find common.jar (android.arch.core:common:1.0.0)

    Error:Could not find common.jar (android.arch.core:common:1.0.0). Searched in the following location ...

  9. docker 部署Spring Boot:Docker化Spring Boot应用程序

    第一章 1.创建项目存放目录 mkdir /root/sproot -p 2.准备好Spring Boot应用程序 jar 包 testrest.jar 第二章 1. 安装docker 在所有节点执行 ...

  10. nodejs安装及npm模块插件安装路径配置

    在学习完js后,我们就要进入nodejs的学习,因此就必须配置nodejs和npm的属性了. 我相信,个别人在安装时会遇到这样那样的问题,看着同学都已装好,难免会焦虑起来.于是就开始上网查找解决方案, ...