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 3064

    1:前n项和公式:1+2+3+...+n = n*(n+1)/2 2:前n项平方和公式:1^2+2^2+.........+n^2=n*(n+1)*(2n+1)/6 #include<stdio ...

  2. group by语句,聚合函数与其他语句(关系,执行过程)

    (本文一切基于SQL SERVER 2008 R2) 先来看一个语句执行过程发生的错误提示: 消息 8120,级别 16,状态 1,第 2 行 选择列表中的列 'SC.CNO' 无效,因为该列没有包含 ...

  3. 【ACM】hdu_1808_Halloween treats_201308132022

    Halloween treats Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. BZOJ——T 1800: [Ahoi2009]fly 飞行棋

    Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1767  Solved: 1395[Submit][Status][Discuss] Descripti ...

  5. Java 和JS Base64加密

    项目在登录.注册等场景实现时,经常会用到用户信息前端加密,然后项目后端二次解密,避免信息直接在浏览器上以明文显示. 本文主要介绍了base64加密的方式处理代码,不支持中文 源码如下: base64. ...

  6. [转]十五天精通WCF——第五天 你需要了解的三个小技巧

    一: 服务是端点的集合 当你在开发wcf的时候,你或许已经注意到了一个service可以公布多个endpoint,确实是这样,在wcf中有一句很经典的话,叫做“服务是端点的集合",就 比如说 ...

  7. data guard 的redo 传输

    data guard 通过把redo从primary数据库传输到standby数据库并应用在standby数据库来实现自己的功能. redo 传输是有2种模式 1. 同步 sync 2. 异步 asy ...

  8. php 数组 array()

    定义和用法 array() 创建数组,带有键和值.如果在创建数组时省略了键,则生成一个整数键,默认从 0 开始,然后以 1 进行递增. 用 array() 创建一个数组,可使用 => 来分隔键和 ...

  9. iphone照片查看器

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  10. IOS_OC_Category

    1.Category概述 那的Category的使用场景有那些呢: 1.类包括了非常多个方法实现,而这些方法须要不同团队的成员来实现 2.当你在使用基础类库中的类时,你不想继承这些类而仅仅想加入一些方 ...