POJ 3020 Antenna Placement
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
Svenskt Mästerskap i Programmering/Norgesmesterskapet 2001
将每个点拆点
构建二分图
求一下最小边覆盖
最小边覆盖=点数-最大匹配数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=1001;
int vis[MAXN];
int link[MAXN];
int map[MAXN][MAXN];
int N,M;
bool dfs(int x)
{
for(int i=1;i<=N*M;i++)
{
if(map[x][i]&&!vis[i])
{
vis[i]=1;
if(!link[i]||dfs(link[i]))
{
link[i]=x;
return 1;
}
}
}
return 0;
}
int belong[MAXN][MAXN];
char a[MAXN][MAXN];
int xx[5]={0,-1,+1,0,0};
int yy[5]={0,0,0,-1,+1};
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int Test;
scanf("%d",&Test);
while(Test--)
{
memset(link,0,sizeof(link));
memset(map,0,sizeof(map));
memset(a,0,sizeof(a));
scanf("%d%d",&N,&M);
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
belong[i][j]=(i-1)*M+j;
for(int i=1;i<=N;i++)
scanf("%s",a[i]+1);
int tot=0;
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
{
if(a[i][j]=='*')
{
tot++;
for(int k=1;k<=4;k++)
{
int wx=i+xx[k],wy=j+yy[k];
if(wx>=1&&wx<=N&&wy>=1&&wy<=M&&a[wx][wy]=='*')
map[ belong[i][j] ][ belong[wx][wy] ]=1;
}
}
}
// for(int i=1;i<=N;i++,puts(""))
// for(int j=1;j<=M;j++)
// printf("%d ",belong[i][j]);
int ans=0;
for(int i=1;i<=N*M;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%dn",tot-ans/2 );
}
return 0;
}
- Linux+Nginx/Apache/Tomcat新增SSL证书,开启https访问教程
- golang 使用时间通过md5生成token
- golang中对map操作类
- Nginx在线服务状态下平滑升级或新增模块的详细操作记录
- 【Dev Club分享】微信读书iOS性能优化
- [svn: E155004]svn update报database is locked错误的解决办法
- WordPress高亮插件:Crayon Syntax Highlighter加载优化
- 深入理解 ButterKnife,让你的程序学会写代码
- JS+CSS让网站嗨起来,博客要被玩坏了!
- Linux系统zip压缩命令详细参数,附文件排除选项的正确用法
- 浅谈Android自定义锁屏页的发车姿势
- 移动App入侵与逆向破解技术-iOS篇
- 启用WP Super Cache纯代码版本之后的一些优化措施
- WP Super Cache静态缓存插件纯代码版(兼容多域名网站)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- RESTful API 设计最佳实践
- Spring 是如何解决循环依赖的?
- 移动webhead参数
- 看了这篇泛型,下次设计链表别傻傻的用int 表示node节点的值了
- 标准TensorFlow格式 TFRecords
- LeetCode 05最长回文子串
- 基于NCNN的3x3可分离卷积再思考盒子滤波
- [译]Buidler 新手教程
- tf.train.shuffle_batch函数解析
- 网页小图标Favicon
- ASP.net Core MVC项目给js文件添加版本号
- 多目标优化非支配关系实现
- linux之shell
- linux下的定时任务处理
- 10 个用纯 Javascript 实现的好用插件