POJ——T 3020 Antenna Placement
http://poj.org/problem?id=3020
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9844 | Accepted: 4868 |
Description
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
Output
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
#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的更多相关文章
- POJ 题目3020 Antenna Placement(二分图)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7011 Accepted: 3478 ...
- (poj)3020 Antenna Placement 匹配
题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 3020 Antenna Placement 【最小边覆盖】
传送门:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total ...
- 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement
题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...
- POJ 3020 Antenna Placement【二分匹配——最小路径覆盖】
链接: http://poj.org/problem?id=3020 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
Antenna Placement Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- POJ 3020 Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
随机推荐
- [luogu]P3572 [POI2014]PTA-Little Bird(单调队列)
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...
- Nutch的配置(使用MySQL作为数据存储)
首先先从http://www.apache.org/dyn/closer.cgi/nutch/下载安装包 这里假定nutch的根目录为:${APACHE_NUTCH_HOME} 配置${APACHE_ ...
- Linux 网络搭建
如果系统环境崩溃. 调用/usr/bin/vim /etc/profile Windows 1 本地连接使用固定IP vmware 8 2 修改Windows的hosts地址 ...
- 51nod-1359: 循环探求
[传送门:51nod-1359] 简要题意: 给出n和k,求出最小的x满足$n^{x}≡n(mod\;10^{k})$ 题解: 真是一道有(du)趣(liu)题目 首先我们设X[k-1]为$n^{x} ...
- artTemplate的使用
引言 腾讯的前端模板引擎,不逊于doT.js 1.引入 <script type="text/javascript" src="../plugin/artTempl ...
- 91.Bower : ENOGIT git is not installed or not in the PATH 解决方法
转自:https://www.haorooms.com/post/bower_error 今天在用bower安装依赖的时候,出现了Bower : ENOGIT git is not installed ...
- spring中bean标签factory-method和factory-bean)详解工厂方法(factory-method和factory-bean)
转自:http://blog.sina.com.cn/s/blog_6d3c1ec601019f3j.html A.factory-method The name of a factory metho ...
- BZOJ 2096 单调队列
思路: 偷懒用的STL //By SiriusRen #include <deque> #include <cstdio> using namespace std; struc ...
- ksh简介
-- Start 什么是 Shell 如果把 Linux 比作一个蛋,那么 Shell 就是蛋壳,我们需要通过 Shell 来使用系统. Shell 的种类 最早的 Shell 是 Bourne Sh ...
- java中对象和对象引用的区别
1.何谓对象? 在Java中有一句比较流行的话,叫做“万物皆对象”,这是Java语言设计之初的理念之一.要理解什么是对象,需要跟类一起结合起来理解.下面这段话引自<Java编程思想>中的一 ...