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. 【1657: [蓝桥杯][算法训练VIP]】统计单词个数

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dp[i][j]表示前i个字符分成j个部分的最多匹配单词个数. 则dp[i][j] = dp[prei][j-1] + get_num(pr ...

  2. RSA算法求明文

    #注:gmpy2 的安装请参考 http://www.cnblogs.com/gwind/p/8000570.html# -*- coding: utf-8 -*- import gmpy2 prin ...

  3. 如何将变量id添加到jquery的选择器中

    今天在做广州仲裁委员会的系统时这样的一个需求,需要在页面一加载的时候查询各个项目的案件数,这里有很多个项目,一开始我是这样写的: 代码如下: $.get(assignedCaseUrl,functio ...

  4. [bzoj1131][POI2008]Sta_树形dp

    Sta bzoj-1131 POI-2008 题目大意:给定一棵n个点的树,求一个根,使得深度和最大. 注释:$1\le n \le 10^6$. 想法:扭一扭即可. 扭的时候看看这个点当没当过根. ...

  5. [bzoj1598][Usaco08Mar]牛跑步_A*_Dijkstra

    牛跑步 bzoj-1598 题目大意:给你n个点,m条边的有向图.求从1到n的严格的第k短路. 注释:$1\le n\le 1000$,$1\le m \le 10,000$,$1\le k \le ...

  6. redo allocation latch redo copy latch

    这两个latch 是干什么的一直有点迷糊,刚才上网查了一下,总结如下: redo allocation latch 在Log Buffer中分配内存空间时需要获取Redo allocation lat ...

  7. firedac的数据序列和还原单元(Data.FireDACJSONReflect.pas)之拷贝FIREDAC数据集

    使用流做中转 procedure CopyDataSet(const ASource, ADest: TFDAdaptedDataSet);var LStream: TStream;begin LSt ...

  8. linux给文件或文件夹加入apache权限

    系统环境:ubuntu11.10/apache2/php5.3.6 在LAMP环境中,測试一个简单的php文件上传功能时,发现/var/log/apache2/error.log中出现例如以下php警 ...

  9. jQuery EasyUI 1.4更新记录

    问题: menu:修复当删除一个menu项时.menu高度不准确. datagrid:修复当datagrid宽度太小时,fitColumns方法不能使用. 改进: 1.为easyui全部组件新增了自适 ...

  10. 开发DataSnapserver

     在上次的文章中讨论了怎样把传统的Delphi 主从架构应用程序逐渐转换为DataSnap JSONserver.在本篇文章中让我们正式讨论怎样使用Delphi XE开发DataSnap/REST ...