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
题意:一个n*m的平面内有一些点,有1*2的纸条,可以横放或竖放,求最少用多少张纸条才能覆盖所有点?
题解:纸条相当于一条边,上道题求得为覆盖所有边的最小点数,这道题则逆其道而行,可转化为覆盖所有点的最小边数,即最小路径覆盖
二分图中最小路径覆盖=点数-最小边覆盖
然后就可以用匈牙利跑了~
代码如下:
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; vector<int> g[];
int vis[],link[];
int map[][],n,m,cnt,ttt;
char c[][]; int dfs(int x)
{
int sz=g[x].size();
for(int k=;k<sz;k++)
{
int y=g[x][k];
if(!vis[y])
{
vis[y]=;
if(!link[y]||dfs(link[y]))
{
link[y]=x;
return ;
}
}
}
return ;
} int search()
{
memset(link,,sizeof(link));
int tmp=;
for(int i=;i<=cnt;i++)
{
if(dfs(i))
{
memset(vis,,sizeof(vis));
tmp++;
}
}
return tmp;
} int main()
{
scanf("%d",&ttt);
while(ttt--)
{
cnt=;
scanf("%d%d",&n,&m);
memset(map,,sizeof(map));
for(int i=;i<=;i++)
{
g[i].clear();
}
for(int i=;i<=n;i++)
{
scanf("%s",c[i]);
for(int j=;j<m;j++)
{
if(c[i][j]=='o')
{
map[i][j+]=;
}
else
{
map[i][j+]=++cnt;
}
}
} for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(map[i][j])
{
if(map[i][j+])
{
g[map[i][j]].push_back(map[i][j+]);
}
if(map[i][j-])
{
g[map[i][j]].push_back(map[i][j-]);
}
if(map[i+][j])
{
g[map[i][j]].push_back(map[i+][j]);
}
if(map[i-][j])
{
g[map[i][j]].push_back(map[i-][j]);
}
}
}
}
int ans=search();
int x=cnt-ans/;
printf("%d\n",x);
}
}

 

POJ3020 Antenna Placement(二分图最小路径覆盖)的更多相关文章

  1. POJ 3020 Antenna Placement (二分图最小路径覆盖)

    <题目链接> 题目大意:一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,每放置一个基站,至多可以覆盖相邻的两个城市.问至少放置多少个基站才能使得所有的城市都覆盖无线? 解题分析: ...

  2. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

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

  3. POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】

    Antenna Placement Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  4. poj 3020 Antenna Placement (最小路径覆盖)

    二分图题目 当时看到网上有人的博客写着最小边覆盖,也有人写最小路径覆盖,我就有点方了,斌哥(kuangbin)的博客上只给了代码,没有解释,但是现在我还是明白了,这是个最小路径覆盖(因为我现在还不知道 ...

  5. [bzoj2150]部落战争_二分图最小路径覆盖

    部落战争 bzoj-2150 题目大意:题目链接. 注释:略. 想法: 显然是最小路径覆盖,我们知道:二分图最小路径覆盖等于节点总数-最大匹配. 所以我们用匈牙利或者dinic跑出最大匹配,然后用总结 ...

  6. Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖

    Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coord ...

  7. POJ3020Antenna Placement(最小路径覆盖+重在构图)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7788   Accepted: 3880 ...

  8. 【HDU3861 强连通分量缩点+二分图最小路径覆盖】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意:一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.有边u到v以及有 ...

  9. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

随机推荐

  1. MySQL中创建用户与授权

    参考地址:http://blog.csdn.net/gebitan505/article/details/51726649 一.创建用户(使用root用户登录进入mysql命令行) create us ...

  2. 【Http认证方式】——Basic认证

    访问请求:http://192.168.2.113:8080/geoserver/rest/workspaces时,浏览器弹出窗口需要输入用户名和密码  ,并且,如果不输入或者输入错误,浏览器返回  ...

  3. Source Insight中文字体设置

    Source Insight是一个面向项目开发的程序编辑器和代码阅读工具,它拥有内置的对C/C++, C#和Java等程序的分析,分析你的源代 码并在你工作的同时动态维护它自己的符号数据库,并自动为你 ...

  4. 【转】 Pro Android学习笔记(九七):BroadcastReceiver(1):基础小例子

    目录(?)[-] 基础小例子 发送Broadcast intent 运行情况 应用间的广播 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog ...

  5. 特别注意: range.Text.ToString(); 和 range.Value2.ToString(); 的区别

    如果Excell的单元格里面是日期,前面显示2015年05月10日:后面的显示42134 也就是说:Text 和Value2的不同. using System; using System.Data; ...

  6. leetcode832

    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) { vector& ...

  7. scss基本用法总结

    工作的时候天天用,面试的时候却没了思路,这就是懒得下场.多总结,多整理,才是成长得王道啊.最近换工作,把以前该整理得工作梳理一遍. 一.定义变量与引用 $color: #f00; $a-color: ...

  8. openGL 纹理05

    纹理(Texture) 为了能够把纹理映射(Map)到三角形上,我们需要指定三角形的每个顶点各自对应纹理的哪个部分. 这样每个顶点就会关联着一个纹理坐标(Texture Coordinate) 用来标 ...

  9. dom方式解析xml文件的步骤

    使用java类即可

  10. Timer中的重要函数