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. DPDK l2fwd

    dpdk的l2fwd主要做二层转发,代码分析如下. #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  2. 入门教程:.NET开源OpenID Connect 和OAuth解决方案IdentityServer v3 介绍 (一)

    现代的应用程序看起来像这样: 典型的交互操作包括: 浏览器与 web 应用程序进行通信 Web 应用程序与 web Api (有时是在他们自己的有时代表用户) 通信 基于浏览器的应用程序与 web A ...

  3. EditText实现输入表情

    EditText实现输入表情 一.简介 editText是TextView的子类,TextView能用的工具EditText都能用,这里就是editText利用SpannableString的Imag ...

  4. SPOJ - VLATTICE

    链接 题意:三维平面,找从(0,0,0)看(n,n,n)能看到的点 题解:很明显就是求gcd(i,j,k)==1的(i,j,k)对数,改一下公式即可,记得要算平行坐标轴的三个平面,还有含0的三个坐标 ...

  5. Docker 应用实例

    Docker安装Nginx 方法一.通过 Dockerfile构建 创建Dockerfile 首先,创建目录nginx,用于存放后面的相关东西. runoob@runoob:~$ mkdir -p ~ ...

  6. USB转串口WIN8驱动安装

    http://jingyan.baidu.com/article/11c17a2c0bb606f446e39da0.html  //查看百度经验 http://jingyan.baidu.com/ar ...

  7. 修改MAC过程

    首先打开PC的Telnet功能,如下: 对PC设置本地IP 2.cmd→telnet 192.168.1.230(出厂默认IP) 3.root →密码:20...................(公司 ...

  8. 条款5.了解c++默默编写并且调用了哪些函数。

    如果想在一个内含reference成员的class内支持赋值操作,必须自己定义copy assignment操作符.而且面对“内含有const成员的”class,编译器的反应也是相同的,由于更改con ...

  9. 条款20:在传递对象的时候尽量用reference-to-constent来代替,pass-by-value

    注意一下,c++的底层编译器而言,引用类型往往都是由指针来实现出来的,所以pass-by-reference实际意义上往往是传递了一个指针,这对于c++的内置类型来说往往传递一个reference更加 ...

  10. php判断字符串长度 strlen()与mb_strlen()函数

    PHP strlen() 函数 定义和用法 strlen() 函数返回字符串的长度. 语法 strlen(string) 参数:string <?php $str=‘中文a字1符‘; echo ...