POJ 3020 Antenna Placement(最少边覆盖所有点)
来源:互联网 发布:江苏城市频道网络直播 编辑:程序博客网 时间:2024/05/07 01:10
Antenna Placement
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7524 Accepted: 3734
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?
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
27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******
Sample Output
175
*表示城市,相邻的两个城市可以用一个天线覆盖,求覆盖所有点的最小天线数
给每个城市一个编号,相邻的i,j城市记为map[i][j]=1
#include <cstdio>#include <cstring>#include <stdlib.h>#include <algorithm>#include <iostream>#include <cmath>#include <string>#define N 401using namespace std;int x[]= {0,0,1,-1};int y[]= {1,-1,0,0};int map[N][N];int sum;int xx[N],yy[N];int v[N];int dfs(int r){ for(int i=0; i<sum; i++) { if(map[r][i] && !v[i]) { v[i]=1; if(yy[i]==-1 || dfs(yy[i])) { xx[r]=i; yy[i]=r; return 1; } } } return 0;}int Solve(){ int ans=0; memset(xx,-1,sizeof(xx)); memset(yy,-1,sizeof(yy)); for(int i=0; i<sum; i++) { if(xx[i]==-1) { memset(v,0,sizeof(v)); ans+=dfs(i); } } return ans;}int main(){ int T; scanf("%d",&T); while(T--) { int n,m; char s[45][20]; scanf("%d%d",&n,&m); for(int i=0; i<n; i++) cin>>s[i]; sum=0; int t[45][20]; for(int i=0; i<n; i++) //记录城市数目 for(int j=0; j<m; j++) { if(s[i][j]=='*') { t[i][j]=sum++; //给城市编号 } } memset(map,0,sizeof(map)); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(s[i][j]=='*') { for(int k=0; k<4; k++) //相邻4个点是否有城市 { int dx = i+x[k]; int dy = j+y[k]; if(dx>=0 && dx<n && dy>=0 && dy<m && s[dx][dy]=='*') { map[t[i][j]][t[dx][dy]] = 1; } } } } } int ans = Solve(); printf("%d\n",sum-ans/2); } return 0;}
0 0
- POJ 3020 Antenna Placement(最少边覆盖所有点)
- POJ-3020 Antenna Placement(最小点覆盖)
- poj 3020Antenna Placement 最小边覆盖
- poj 3020 Antenna Placement (最小边覆盖)
- POJ 3020 Antenna Placement(最小边覆盖)
- POJ 3020 Antenna Placement (最小边覆盖)
- POJ 3020 — Antenna Placement 最小边覆盖
- POJ 3020 Antenna Placement(无向图最小边覆盖)
- Poj 3020 Antenna Placement【最小边覆盖 匈牙利算法】
- POJ 3020 Antenna Placement (最小边覆盖/最大匹配应用)
- poj 3020 Antenna Placement (最小路径覆盖)
- POJ 3020 Antenna Placement(二分图最小路径覆盖)
- poj 3020 Antenna Placement (最小路径覆盖)
- POJ 3020 Antenna Placement (最小路径覆盖)
- POJ 3020:Antenna Placement(最小路径覆盖)
- POJ 3020 Antenna Placement(二分匹配+拆点)
- poj 3020 Antenna Placement (最小路径覆盖, 匈牙利算法, 拆点形成二分图)
- poj 3020 Antenna Placement
- 查看 SELinux状态及关闭SELinux
- NSIS 简易教程
- 安全应急之网络异常排查win&linux-20150805
- C++ Builder XE8 安卓开发之使用TidTCPClient控件获取接收数据长度的方法
- 计蒜客 难题题库 218 配对元素
- POJ 3020 Antenna Placement(最少边覆盖所有点)
- 插值法公式倒推回有理状态
- 基本固件框架的追踪研读之USB控制传输
- 如何实现鼠标放在图片上出现文字说明效果?
- jquery 动态创建元素,在元素山添加事件
- 剑指offer_面试题16_反转链表(两种方法)
- 层次打印二叉树
- UVA 10723 Cyborg Genes
- 幽默