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

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

field=source&key=Svenskt+M%C3%A4sterskap+i+Programmering%2FNorgesmesterskapet+2001" style="text-decoration:none">Svenskt Mästerskap i
Programmering/Norgesmesterskapet 2001

ac代码

#include<stdio.h>
#include<string.h>
int map[1010][1010],cut[1010][1010];
int link[101000],vis[101000],x,y,cnt;
char str[1010][1010];
int dfs(int u)
{
int i;
for(i=1;i<=cnt;i++)
{
if(!vis[i]&&map[u][i])
{
vis[i]=1;
if(link[i]==-1||dfs(link[i]))
{
link[i]=u;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,i,j;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s",str[i]);
}
// int x=0
cnt=0;
memset(cut,0,sizeof(cut));
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(str[i][j]=='*')
cut[i][j]=++cnt;
}
}
memset(map,0,sizeof(map));
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(cut[i][j])
{
if(j>0&&cut[i][j-1])
map[cut[i][j]][cut[i][j-1]]=1;
if(i>0&&cut[i-1][j])
map[cut[i][j]][cut[i-1][j]]=1;
if(j<m-1&&cut[i][j+1])
map[cut[i][j]][cut[i][j+1]]=1;
if(i<n-1&&cut[i+1][j])
map[cut[i][j]][cut[i+1][j]]=1;
}
}
}
memset(link,-1,sizeof(link));
int ans=0;
for(i=1;i<=cnt;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",cnt-ans/2);
}
}

POJ 题目3020 Antenna Placement(二分图)的更多相关文章

  1. [POJ] 3020 Antenna Placement(二分图最大匹配)

    题目地址:http://poj.org/problem?id=3020 输入一个字符矩阵,'*'可行,'o'不可行.因为一个点可以和上下左右四个方向的一个可行点组成一个集合,所以对图进行黑白染色(每个 ...

  2. POJ 3020 Antenna Placement(二分图 匈牙利算法)

    题目网址:  http://poj.org/problem?id=3020 题意: 用椭圆形去覆盖给出所有环(即图上的小圆点),有两种类型的椭圆形,左右朝向和上下朝向的,一个椭圆形最多可以覆盖相邻的两 ...

  3. POJ - 3020  Antenna Placement 二分图最大匹配

    http://poj.org/problem?id=3020 首先注意到,答案的最大值是'*'的个数,也就是相当于我每用一次那个技能,我只套一个'*',是等价的. 所以,每结合一对**,则可以减少一次 ...

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

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

  5. (poj)3020 Antenna Placement 匹配

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

  6. POJ——T 3020 Antenna Placement

    http://poj.org/problem?id=3020 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9844   A ...

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

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

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

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

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

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

随机推荐

  1. codevs1060 搞笑世界杯(概率dp)

    1060 搞笑世界杯  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description 随着世界杯小组赛的结束,法国,阿根廷等世界 ...

  2. 【Python】循环语句

    while循环 当条件成立时,循环体的内容可以一直执行,但是避免死循环,需要有一个跳出循环的条件才行. for循环 遍历任何序列(列表和字符串)中的每一个元素 >>> a = [&q ...

  3. Redis学习笔记(二):Redis集群

    集群通过分片(sharding)来进行数据共享,并提供复制和故障转移功能.   1.节点 一个节点就是一个运行在集群模式下的Redis服务器.启动Redis服务器时,通过判断cluster-enabl ...

  4. CSS多列布局(实例)

    前言 一列布局 二列布局 三列布局 1 一列布局 一列布局: HTML部分 <!DOCTYPE html> <html> <head> <meta chars ...

  5. Django models 常用字段类型

    1.CharField字符串字段,存较短的字符串,长文本要用TextField.必须的参数:max_length 字符的最大长度2.TextField容量很大的文本字段.admin中用 <tex ...

  6. Android java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader......couldn't find "libweibosdkcore.so

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ ...

  7. angular js 球星

    <!DOCTYPE html>   <html lang="en">   <head>   <meta charset="UTF ...

  8. [转]VIM字符替换

    语法为 :[addr]s/源字符串/目的字符串/[option] 全局替换命令为::%s/源字符串/目的字符串/g [addr] 表示检索范围,省略时表示当前行. 如:"1,20" ...

  9. 虚拟DOM介绍

    [转自]:https://www.jianshu.com/p/616999666920 为什么需要虚拟DOM 先介绍浏览器加载一个HTML文件需要做哪些事,帮助我们理解为什么我们需要虚拟DOM.web ...

  10. EL截取url中参数

    function getUrlString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*) ...