POJ3020-Antenna Placement
来源:互联网 发布:电力工程报价软件 编辑:程序博客网 时间:2024/05/05 05:18
Antenna Placement
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9411 Accepted: 4646
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
题意:给出一个地图,'*'是城市,'o'是空地,有n个城市,现在这n个城市都要覆盖无线,若放置一个基站,那么它至多可以覆盖相邻的两个城市,问至少放置多少个基站才能使得所有的城市都覆盖无线
解题思路:二分图,将格子按黑白标记后,再将含'*'的格子按黑白分成两组,相邻的格子建边,再算出点独立数
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>#include <functional>#include <bitset>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int n,m;int xn,yn;int x[1525],y[1525];int s[2525],nt[20050],e[20050];int visit[1525];char ch[50][50];int mp[50][50];int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};bool path(int k){ for(int i=s[k];~i;i=nt[i]) { int ee=e[i]; if(!visit[ee]) { visit[ee]=1; if(y[ee]==-1||path(y[ee])) { y[ee]=k; x[k]=ee; return 1; } } } return 0;}void MaxMatch(){ int ans=0; memset(x,-1,sizeof x); memset(y,-1,sizeof y); for(int i=1;i<xn;i++) { if(x[i]==-1) { memset(visit,0,sizeof visit); if(path(i)) ans++; } } printf("%d\n",xn+yn-ans-2);}int main(){ int t; scanf("%d",&t); while(t--) { xn=yn=1; scanf("%d %d",&n,&m); int cnt=1; memset(s,-1,sizeof s); for(int i=1;i<=n;i++) { scanf("%s",ch[i]+1); for(int j=1;j<=m;j++) { if(ch[i][j]=='*') { if((i+j)%2==1) mp[i][j]=xn++; else mp[i][j]=yn++; } else mp[i][j]=0; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(!mp[i][j]||!((i+j)%2)) continue; 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||!mp[xx][yy]) continue; nt[cnt]=s[mp[i][j]],s[mp[i][j]]=cnt,e[cnt++]=mp[xx][yy]; } } } MaxMatch(); } return 0;}
0 0
- POJ3020 Antenna Placement
- poj3020 Antenna Placement
- poj3020 Antenna Placement
- Antenna Placement poj3020
- poj3020-Antenna Placement
- POJ3020 Antenna Placement
- poj3020 Antenna Placement
- 【poj3020】 Antenna Placement
- POJ3020-Antenna Placement
- POJ3020 Antenna Placement
- POJ3020 Antenna Placement
- poj3020——Antenna Placement
- POJ3020 Antenna Placement 二分匹配
- poj3020--Antenna Placement(二分匹配)
- POJ3020--Antenna Placement--二分图最大匹配
- POJ3020 Antenna Placement 解题报告--匈牙利
- poj3020 Antenna Placement(二分图)
- poj3020-Antenna Placement-最小点覆盖
- [学习日志][2-2-5][Eclipse集成开发环境]
- 磁盘调度算法模拟
- Unity协程(Coroutine)管理类——TaskManager工具分享
- oc——类——声明 定义 实现
- insmod不匹配
- POJ3020-Antenna Placement
- 人脸特征点的初始化
- 把Notepad++的tab设置为四个空格
- DevOps的八荣八耻
- iOS 真机测试查看APP沙盒
- UVA 11082 Matrix Decompressing (最大流)
- iOS基础——通知代理之NSNotificationCenter、Delegate
- 用户空间访问 rtc
- arpg怎么做战斗回放