Antenna Placement
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8721   Accepted: 4330

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 最小路径匹配=点数—最大匹配数。
最后最大匹配数为匈牙利算法求得结果的一半,原因是建的图为无向图。
此题建模的思想可以学习借鉴。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<map>
using namespace std; int dir[][]= {-,,,,,,,-};
int mapp[][];
int bimap[][],link[];
int vis[];
int cnt=,m,n; bool inside(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m)
return ;
return ;
}
bool dfs(int x)
{
for(int i=; i<cnt; i++)
if(bimap[x][i]&&!vis[i])
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return true;
}
}
return false;
} int ans;
void solve()
{
memset(link,-,sizeof(link));
for(int i=; i<cnt; i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
} int main()
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
cnt=;
memset(mapp,,sizeof(mapp));
memset(bimap,,sizeof(bimap));
scanf("%d%d",&n,&m);
getchar();
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
char ch;
scanf("%c",&ch); if(ch=='*')
mapp[i][j]=cnt++;
else
mapp[i][j]=;
}
getchar();
}
for(int i=; i<n; i++)
for(int j=; j<m; j++)
{
if(mapp[i][j]>)
for(int k=; k<; k++)
{
int xx=i+dir[k][];
int yy=j+dir[k][];
if(mapp[xx][yy]&&inside(xx,yy))
{
bimap[mapp[i][j]][mapp[xx][yy]]=;
//bimap[mapp[xx][yy]][mapp[i][j]]=1;
}
}
}
ans=;
solve();
//cout<<ans<<endl;
printf("%d\n",cnt--ans/);
}
return ;
}

POJ_3020_最小路径覆盖的更多相关文章

  1. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. loj 1429(可相交的最小路径覆盖)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1429 思路:这道题还是比较麻烦的,对于求有向图的可相交的最小路径覆盖,首先要解决成环问 ...

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

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

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

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

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

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

  6. POJ 3020 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...

  7. 【wikioi】1904 最小路径覆盖问题(最大流+坑人的题+最小路径覆盖)

    http://wikioi.com/problem/1904/ 这题没看数据的话是一个大坑(我已报告官方修复了),答案只要求数量,不用打印路径...orz 最小路径覆盖=n-最大匹配,这个我在说二分图 ...

  8. hiho 第118周 网络流四·最小路径覆盖

    描述 国庆期间正是旅游和游玩的高峰期. 小Hi和小Ho的学习小组为了研究课题,决定趁此机会派出若干个调查团去沿途查看一下H市内各个景点的游客情况. H市一共有N个旅游景点(编号1..N),由M条单向游 ...

  9. 【网络流24题----03】Air Raid最小路径覆盖

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

随机推荐

  1. hdu 4971 多校10最大权闭合图

    /* 很明显的最大权闭合图题 */ #include<stdio.h> #include<string.h> #include<queue> using names ...

  2. sgu 176 有源汇有上下界的最小流模板题

    /*参考博文:http://hi.baidu.com/dragon_eric123/item/82e259200ece744046996282 有上下界的有源最小流 */ #include<st ...

  3. 嵌入式linux和嵌入式android系统有什么区别和联系?

    转自:http://bbs.eeworld.com.cn/thread-430437-1-1.html 这个问题很多人问,尤其是初入嵌入式的菜鸟.其实大家都认为android是java,已经不是lin ...

  4. 调用BPL包中的函数

    BPL就是一种DLL,DLL的EXPORTS和GETPROCADDRESS()在BPL中一样好使. 要调用BPL中的方法也和调用DLL的一样.代码略.

  5. java.text.ParseException: Unparseable date: &quot;2015-06-09 hh:56:19&quot;

    1.错误描写叙述 [DEBUG:]2015-06-09 16:56:19,520 [-------------------transcation start!--------------] java. ...

  6. hdu1068 Girls and Boys --- 最大独立集

    有一个集合男和一个集合女,给出两集合间一些一一相应关系.问该两集合中的最大独立集的点数. 最大独立集=顶点总数-最大匹配数 此题中.若(a,b)有关.则(b,a)有关.每个关系算了两次,相当于二分图的 ...

  7. 『Spring.NET+NHibernate+泛型』框架搭建之Model(二)

    依照搭建项目的顺序来比較好描写叙述一些,我一般先搭建实体层,本节内容纯属于NHibernate范畴.先上图和代码,然后对着图和代码逐一解说,以角色表为例:   T_Role表: 数据库表设计非常eas ...

  8. 【Linux学习】Ubuntu下 sambaserver搭建

    1.安装samba,smbfs 2.配置smb.conf文件 配置文件之前须要先备份一下须要配置的文件(养成好的习惯) 输入命令: 进入到smb.conf文件里,在文件的最后加入下列语句 保存后.退出 ...

  9. OpenCV 学习(计算图像的直方图)

    OpenCV 计算图像的直方图 计算图像的直方图是图像处理领域一个非经常见的基本操作. OpenCV 中提供了 calcHist 函数来计算图像直方图.只是这个函数说实话挺难用的,研究了好久才掌握了些 ...

  10. Android EditText技巧总结

    一.默认不获取焦点: 在布局文件的父控件中,设置如下属性: android:focusable="true" android:focusableInTouchMode=" ...