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. BZOJ 4010 拓扑排序+heap

    思路: 反向图求最大拓扑序 反向输出 //By SiriusRen #include <queue> #include <cstdio> #include <cstrin ...

  2. C - New Year Candles

    Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...

  3. Android 应用安装成功之后删除apk文件

    问题: 在应用开发中遇到需要这样的需求:在用户下载我们的应用安装之后删除安装包. 解决: android会在每个外界操作APK的动作之后发出系统级别的广播,过滤器名称: android.intent. ...

  4. ie8及其以下版本兼容性问题之input file隐藏上传文件

    文件上传时,默认的file标签很难看,而且每个浏览器下都有很大差距.因此我们基本都把真正的file标签给隐藏,然后创建一个标签来替代它.但是由于IE出于安全方面的考虑上传文件时必须点击file的浏览按 ...

  5. 【PostgreSQL-9.6.3】创建、修改、删除数据库

    1.创建数据库 create database database_name; 2.修改数据库的名称 alter database database_name rename to new_databas ...

  6. hibernate_02_session介绍

    什么是session? hibernate的session对象就相当于jdbc的connection.我们对数据库的操作(增删改等)都是使用的session方法. 写一个java类 package c ...

  7. python 上手

    1.安装模块 cmd---“pip install [模块名]” 2.爬虫常用模块 requests beautifulsoup4 3.检查已安装的模块 cmd ---"pip list&q ...

  8. python3 str类型

    python3 的str就是unicode,只有encode函数,调用encode返回的是bytes. bytes只有decode函数,调用decode返回的是str.

  9. logger日志

    Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调试 ERROR 错误事件可能仍然允许应用程序继续运行 FATAL 指定非常严重的错误事件,这可能导致应用 ...

  10. tomcat实现连接数据库

    192.168.30.23mkdir  /web/webapptar xf SLSaleSystem.tar.gz -C /web/webappls /web/wenbappvim /usr/loca ...