POJ3020 Antenna Placement
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9586 | Accepted: 4736 |
Description
![](http://poj.org/images/3020_1.jpg)
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
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
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 <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int ha[MAXN][MAXN];
char s[MAXN];
int dir[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,n,k,x,y,T;
int q=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
int cnt=0;
memset(ha,-1,sizeof ha);
for(int i=0; i<n; i++)
{
scanf("%s",s);
for(int j=0; j<m; j++)
{
if(s[j]=='*')
ha[i][j]=cnt++;
}
}
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
if(ha[i][j]!=-1)
{
for(int k=0; k<4; k++)
{
int xx=i+dir[k][0];
int yy=j+dir[k][1];
if(xx>=0&&xx<n&&yy>=0&&yy<m&&ha[xx][yy]!=-1)
{
g[ha[i][j]][ha[xx][yy]]=1;
}
} }
uN=vN=cnt;
printf("%d\n",cnt-hungary()/2); }
return 0;
}
POJ3020 Antenna Placement的更多相关文章
- poj3020 Antenna Placement 匈牙利算法求最小覆盖=最大匹配数(自身对应自身情况下要对半) 小圈圈圈点
/** 题目:poj3020 Antenna Placement 链接:http://poj.org/problem?id=3020 题意: 给一个由'*'或者'o'组成的n*m大小的图,你可以用一个 ...
- POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖
题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K ...
- POJ3020——Antenna Placement(二分图的最大匹配)
Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...
- POJ3020 Antenna Placement(二分图最小路径覆盖)
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...
- POJ 3020 Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5645 Accepted: 2825 Des ...
- Antenna Placement(匈牙利算法 ,最少路径覆盖)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6991 Accepted: 3466 ...
- poj 3020 最短路径覆盖 Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7329 Accepted: 3635 ...
- Antenna Placement
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7574 Accepted: 3762 Des ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
随机推荐
- c# 上传excel数据总结(一)线程的使用
1: 因为程序涉及到上传,开始暂停,继续,删除, thread 在老版本用使用th.Abort(); th.Resume(); 停止 恢复 th.Suspend(); 挂起 猛的一看挺合适啊..但微 ...
- 织梦文章里面的图片alt和title属性,用文章标题自动替换
把{dede:field.body/}改成{dede:field.body runphp=yes}global $dsql,$id,$aid;$myid = isset($id) ? $id : $a ...
- PHP——explode的应用(获取字符串,拆为下拉列表)
<?php //定义有默认值的函数 function Main3($f=5,$g=6) { echo $f*$g; } Main3(2,3); echo "<br />&q ...
- javascript 高级程序设计 六
上一节还有一个注意的地方:建议所有函数的必需参数使用命名参数,而非必须的参数使用对象来封装. 通过这几天的读书,发现了一个深入了解所学知识的一个捷径——读书.本来我在计算机这方法的所有知识一般都是从视 ...
- a[i++]
今天才知道,a[i++]到底是什么意思:: 其实也很简单了,就是a[i]的值还是a[i],然后i自增1: 把这篇博客当作平常各种错题博客吧,把各种从网上抄的代码不懂的地方写到这个地方算了 ====== ...
- UI设计教程学习分享:APP布局
一.宫格布局 这种APP信息布局方式也是我们目前最常见的一种方式,也是符合用户习惯和黄金比例的设计方式,最知名的就是锤子手机的界面设计.锤子手机界面设计欣赏知名的APP设计采用的九宫格.六宫格等方式布 ...
- Spring IOC(七)类型推断
Spring IOC(七)类型推断 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 容器中可以根据 bean ...
- Maximum Average Subarray I LT643
Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...
- javase高级技术 - 泛型
在写案例之前,先简单回顾下泛型的知识 我们知道,java属于强变量语言,使用变量之前要定义,并且定义一个变量时必须要指明它的数据类型,什么样的数据类型赋给什么样的值. 所谓“泛型”,就是“宽泛的数据类 ...
- datagrid 扩展 页脚 合计功能
效果图:合计信息展示在页脚中(showFooter:true) code: <!DOCTYPE html> <html> <head> <meta chars ...