POJ3020 Antenna Placement
来源:互联网 发布:qq飞车高压数据 编辑:程序博客网 时间:2024/05/18 21:07
Antenna Placement
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10015 Accepted: 4950
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
题意:一个矩形中,有N个城市’*’,现在这n个城市都要覆盖无线,若放置一个基站,那么它至多可以覆盖相邻的两个城市。
问至少放置多少个基站才能使得所有的城市都覆盖无线?
这个题和HDU4185的构图方式一模一样,就不详细介绍了。
这个是最小边覆盖问题, 最小边覆盖= 最大独立集 = n - 最大匹配。emmmm....不过我做的时候没想这么多,我想的就是,一个基站最多管两个相邻的‘*’,最大匹配数*2就是已经匹配上的‘*’的个数,同时最大匹配数就是管俩‘*’的基站个数,那么‘*’的总数减一下最大匹配数*2就是没匹配上的‘*’的个数,这些剩下的‘*’每个都要用一个基站,那么总基站就是最大匹配数加未匹配的‘*’的个数。
代码的话一定要注意数组开多少...
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n,m,ans;char mapp[55][55];int a[55][55],used[450],pp[450];int mappp[450][450];int found(int x){ for(int i=1;i<ans;i++) { if(mappp[x][i]&&!used[i]) { used[i]=1; if(!pp[i]||found(pp[i])) { pp[i]=x; return 1; } } } return 0;}int aa(){ int sum=0; memset(pp,0,sizeof(pp)); for(int i=1;i<ans;i++) { memset(used,0,sizeof(used)); if(found(i))sum++; } return sum;}int main(){ int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(mappp,0,sizeof(mappp)); scanf("%d%d",&n,&m); ans=1; for(int i=0; i<n; i++) { scanf("%s",mapp[i]); for(int j=0; j<m; j++) { if(mapp[i][j]=='*') a[i][j]=ans++; } } for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(mapp[i][j]=='*') { if(i-1>=0&&mapp[i-1][j]=='*') mappp[a[i-1][j]][a[i][j]]=1; if(j+1<m&&mapp[i][j+1]=='*') mappp[a[i][j+1]][a[i][j]]=1; if(i+1<n&&mapp[i+1][j]=='*') mappp[a[i+1][j]][a[i][j]]=1; if(j-1>=0&&mapp[i][j-1]=='*') mappp[a[i][j-1]][a[i][j]]=1; } } } printf("%d\n",ans-1-aa()/2); } 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-最小点覆盖
- Ubuntu 16.04 和 Windows 10 双系统安装教程
- SSL/TLS协议
- Android 竞拍类App节选功能点-高性能更新数据,错位图片闪烁,定时器错乱,定时器时间不同步解决方案
- c++:DFS与BFS详解
- SQL数据库面试题以及答案(50例题)
- POJ3020 Antenna Placement
- USB会议摄像机的重要的网络特性
- json_encode 与 json_decode的区别
- Spring与Mybatis集成
- 文章标题
- 2017-11-17-笔记2-mongoDB
- 用造小人让你彻底搞懂什么是建造者设计模式
- 架构师是大忽悠吗?阿里技术大牛告诉你真相!
- mysql分表和表分区详解