http://poj.org/problem?id=3020

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9844   Accepted: 4868

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

Source

 
题意:*是城市,基站只能安到城市上,可以覆盖上下左右至多2个位置,求最小的基站数、
恶心的建图~
两个点间的覆盖,尝试最小路径覆盖
考虑拆点,将每个城市以及他能覆盖的位置连边,因为两个位置是相互影响的,所以是无向二分图
所以ans=总城市数-最大匹配数/2;
 #include <cstring>
#include <cstdio> using namespace std; char s[];
int fx[]={,,,-};
int fy[]={,,-,};
bool vis[],map[][];
int cnt,match[],if_[][]; int find(int u)
{
for(int v=;v<=cnt;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} int main()
{
int t; scanf("%d",&t);
for(int n,m,ans=;t--;cnt=ans=)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%s",s+);
for(int j=;j<=m;j++)
if(s[j]=='*') if_[i][j]=++cnt;
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(if_[i][j])
for(int k=;k<;k++)
{
int x=i+fx[k],y=j+fy[k];
if(if_[x][y])
map[if_[i][j]][if_[x][y]]=;
}
for(int i=;i<=cnt;i++)
{
if(find(i)) ans++;
memset(vis,,sizeof(vis));
}
printf("%d\n",cnt-ans/);
memset(map,,sizeof(map));
memset(if_,,sizeof(if_));
memset(match,,sizeof(match));
}
return ;
}
 

POJ——T 3020 Antenna Placement的更多相关文章

  1. POJ 题目3020 Antenna Placement(二分图)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7011   Accepted: 3478 ...

  2. (poj)3020 Antenna Placement 匹配

    题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...

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

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

  4. POJ 3020 Antenna Placement 【最小边覆盖】

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

  5. 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement

    题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...

  6. POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】

    链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

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

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

  8. POJ 3020 Antenna Placement

    Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...

  9. POJ 3020 Antenna Placement 最大匹配

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 3182 ...

随机推荐

  1. eclipse引入svn插件,并将项目同步到svn

    1. eclipse中不存在SVN问题的解决 1.1发现Team->Share project 下没有svn. 1.2下载安装svn插件. 选择help->Eclipse Marketpl ...

  2. 楼宇自控-BA系统流程总图

    总结一下过程中的节点和技能,希望能对其他人有所帮助

  3. Webstorm快捷键整理

    Webstorm快捷键整理 F2/Shift F2  下一个/上一个高亮错误 Ctrl+Shift+BackSpace 回到刚刚编辑的地方 Alt+Insert 新建文件,还有其他功能 Ctrl+D ...

  4. Java String内存释放

    Java String内存释放 这是一个坑,Java对于String对象,不进行内存的回收: 处理大数据量的时候,少用String. 与JDK有关系:jdk1.6环境下,内存只占用10M,jdk1.8 ...

  5. 数据结构与算法系列----最小生成树(Prim算法&amp;Kruskal算法)

     一:Prim算法       1.概览 普里姆算法(Prim算法).图论中的一种算法.可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中.不但包含了连通图里的全部顶点(英语:Ve ...

  6. mysql的查询练习1

    1.多表查询

  7. Python菜鸟晋级12----多线程

    Python 多线程 多线程类似于同一时候执行多个不同程序,多线程执行有例如以下长处: 使用线程能够把占领长时间的程序中的任务放到后台去处理. 用户界面能够更加吸引人.这样比方用户点击了一个butto ...

  8. node14---分层结构数据库操作

    /**回调函数(函数作为参数): 0. 外层函数调用的地方,一定是外层函数体先执行,回调函数和普通函数地址一样,然后看函数体规定回调函数怎么执行. 1. 异步时候使用回调函数, 无论是否异步,回调函数 ...

  9. [Android] Android开发优化之——对界面UI的优化(1)

    在Android应用开发过程中,屏幕上控件的布局代码和程序的逻辑代码通常是分开的.界面的布局代码是放在一个独立的xml文件中的,这个文件里面是树型组织的,控制着页面的布局.通常,在这个页面中会用到很多 ...

  10. What is the difference between Web Farm and Web Garden?

    https://www.codeproject.com/Articles/114910/What-is-the-difference-between-Web-Farm-and-Web-Ga Clien ...