Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8924   Accepted: 4428

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
思路:与POJ2446对比。若允许重叠则为最小边覆盖,否则为最大匹配。
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int MAXN=;
int n,m;
vector<int> arc[MAXN];
char mz[MAXN][MAXN];
int vis[MAXN][MAXN];
int dy[]={,,,-};
int dx[]={,,-,}; int match[MAXN],used[MAXN];
bool dfs(int u)
{
for(int i=;i<arc[u].size();i++)
{
int to=arc[u][i];
if(!used[to])
{
used[to]=;
int w=match[to];
if(w==-||dfs(w))
{
match[to]=u;
match[u]=to;
return true;
}
}
}
return false;
}
int max_flow()
{
int ans=;
memset(match,-,sizeof(match));
int limit=n*m;
for(int i=;i<limit;i++)
{
if(match[i]==-)
{
memset(used,,sizeof(used));
if(dfs(i)) ans++;
}
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(vis,,sizeof(vis));
for(int i=;i<MAXN;i++) arc[i].clear();
for(int i=;i<n;i++)
{
scanf("%s",mz[i]);
}
int nodes=;
for(int y=;y<n;y++)
{
for(int x=;x<m;x++)
{
if(mz[y][x]!='*') continue;
nodes++;
vis[y][x]=;
for(int i=;i<;i++)
{
int ny=y+dy[i];
int nx=x+dx[i];
if(<=ny&&ny<n&&<=nx&&nx<m&&!vis[ny][nx]&&mz[ny][nx]=='*')
{
int u=y*m+x;
int v=ny*m+nx;
arc[u].push_back(v);
arc[v].push_back(u);
}
}
}
}
int res=nodes-max_flow();
printf("%d\n",res);
}
return ;
}
												

POJ3020(最小边覆盖)的更多相关文章

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

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

  2. 二分图之最小边覆盖(poj3020)

    题目:poj3020 题意:给出一个图,让你用最少的1*2的纸片覆盖掉图中的全部*出现过的地方. 基本裸的最小边覆盖. 分析: 最小边覆盖 = 点总数 - 最大匹配 所以就是转化为求最大匹配. 跟前面 ...

  3. J - Air Raid - hdu 1151(最小边覆盖)

    题意:给一个有向无环图,求出来最少需要几个士兵可以遍历所有的边. 分析:有向无环图的最小边覆盖 = 点数 - 最大匹配数 为什么是这样的公式??可以思考一下,如果这N个点之间没有边,是不是应该有N个士 ...

  4. [置顶] 白话最小边覆盖总结--附加 hdu1151结题报告

    刚开始看到这个题目的时候就觉得想法很明了,就是不知道如何去匹配... 去网上看了不少人的解题报告,但是对于刚接触“最小边覆盖”的我来说....还是很困难滴....于是自己又开始一如以往学习“最大独立集 ...

  5. hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...

  6. CCPC-Wannafly Winter Camp Day4 Div1 - 最小边覆盖 - [线段树]

    题目链接:https://zhixincode.com/contest/18/problem/C?problem_id=261 样例输入 1 4 21 23 4 样例输出 1 Yes 样例输入 2 4 ...

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

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

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

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

  9. HDU1151:Air Raid(最小边覆盖)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. 使用Executor管理Thread对象详解

    java SE5的java.util.concurrent包中的执行器(Executor)是管理Thread对象的优选方法.使用Executor管理Thread对象可以简化并发编程. Executor ...

  2. mac的一些配置

    1,基础知识 /etc/bashrc :是针对系统所有用户的全局变量,只有root用户才能修改这两个文件,对一般用户来说是他们是只读的.一般用户要想修改它们,可以在命令前加sudo,意思是以Root身 ...

  3. 2015 Syrian Private Universities Collegiate Programming Contest

    A. Window B. Paper Game Des:给你一个矩形集合,一开始只有一个W*H的矩形.每次可以选一个矩形,切成两个并加入集合,长和宽必须是正整数.不能操作者输,求先手赢还是输.(1 ≤ ...

  4. codeforces 831B. Keyboard Layouts 解题报告

    题目链接:http://codeforces.com/contest/831/problem/B 题目意思:给出两个长度为26,由小写字母组成的字符串s1和s2,对于给出的第三个字符串s3,写出对应s ...

  5. ng2 学习笔记(一)

    ng2发布了一段时间,最近才开始着手学习一下,ng2可以说变化海是比较大的,现在写一些学习过程中要注意的点,新手可以参考,大神可以指导: 按照文档来吧: 1.快速开始:没什么可说的,直接上git 克隆 ...

  6. javascript 对象简单介绍(一)

    JavaScript 对象JavaScript 中的所有事物都是对象:字符串.数值.数组.函数...此外,JavaScript 允许自定义对象.所有事物都是对象JavaScript 提供多个内建对象, ...

  7. lambda表达式----使用

    List<THealthKnowledgeEntity> tHealthKnowledgeList = tHealthKnowledgeService.queryList(query);L ...

  8. CCF 201703-3 Markdown

    问题描述   试题编号: 201703-3 试题名称: Markdown 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 Markdown 是一种很流行的轻量级标记语言(lig ...

  9. oracle objects - Materialized views and Synonyms

    Materialized views - 物化视图,不实时查询表,定期更新,查询速度快 视图的更新频率我们可以在这看到:select * from dba_jobs , 一般在创建视图的时候完成的. ...

  10. Maven项目中java类报错-Cannot resolve symbol

    电脑蓝屏了,强制重启之后再打开IDEA里面的项目,所有Java类文件都在报Cannot resolve symbo错误,可以确定所有依赖的包都有引用且jar包没有冲突. 经查询找到这个解决方法: 在I ...