poj3020Antenna Placement
来源:互联网 发布:centos 关闭3306端口 编辑:程序博客网 时间:2024/05/16 09:13
Antenna Placement
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8522 Accepted: 4226
比较详细的讲解
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
Source
Svenskt Mästerskap i Programmering/Norgesmesterskapet 2001
#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <cmath>#define Ll long longusing namespace std;const int N=1e2;vector<int>A[N*N];char s[N][N];int pos[N*N];int num[N][N];int used[N*N];int t,n,m;int k=0;int ch[][2]= {{-1,0},{0,-1},{1,0},{0,1}};bool DFS(int u){ int v; int len=A[u].end()-A[u].begin(); for(int i=0; i<len; i++) { v=A[u][i]; if(!used[v]) { used[v]=1; if(pos[v]==-1||DFS(pos[v])) { pos[v]=u; return 1; } } } return 0;}int hungery(){ memset(pos,-1,sizeof(pos)); int ans=0; for(int i=1; i<=k; i++) { memset(used,0,sizeof(used)); ans+=DFS(i); } return ans;}int main(){ scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(num,-1,sizeof(num)); for(int i=0;i<=N*N;i++) A[i].clear(); k=0; for(int i=0; i<n; i++) { scanf("%s",s[i]); for(int j=0; j<m; j++) { if(s[i][j]=='*') { num[i][j]=++k; } } } int x,y; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(num[i][j]>=0) { for(int p=0; p<4; p++) { x=i+ch[p][0]; y=j+ch[p][1]; if(x>=0&&x<n&&y>=0&&y<m&&num[x][y]>=0) { A[num[i][j]].push_back(num[x][y]); } } } } } printf("%d\n",k-hungery()/2); } return 0;}
0 0
- poj3020Antenna Placement
- poj3020Antenna Placement
- placement new
- placement new
- placement new
- placement new
- placement new
- placement new
- placement new
- placement new
- placement new
- placement new
- placement delete
- placement new
- placement new
- placement new
- new placement
- placement new
- Ubuntu 14.04安装TeamViewer
- 安卓笔记之ViewPager页卡
- 欢迎使用CSDN-markdown编辑器
- Loaders 全面详解及源码浅析
- HTML5 自定义data标签
- poj3020Antenna Placement
- CAD开发小结1
- python:print含有中文的list
- RestTemplate实践
- Handler.post()和handler.sendMessage()总结
- TextView设置 多种颜色,封装好的工具类
- #include <iostream> #include<cstdio> #include<cstring> using namespace std; char s[400001]; int nex
- eclipse中的.project 和 .classpath文件的具体作用
- QT5