【POJ - 3020】Antenna Placement (匈牙利算法,二分图最小边覆盖)

题干:

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? 
 

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

2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*

Sample Output

17
5

题目大意:

*--代表城市,o--代表空地

给城市安装无线网,一个无线网最多可以覆盖两座城市,问覆盖所有城市最少要用多少无线。

解题报告:

有个想法很不错的,帮助理解最小路径覆盖博客

看了这个题解!!我算是彻底懂了无向图的最小边覆盖的求解过程以及为什么是这么求解,但是博客中有个地方说错了,她说是拆点后变成无向图了,,但是其实是原来就是个无向图(也就是说原博客说拆点后变成双向图了更合适),拆点后变成了两个完全一样的无向图,所以可以最后结果直接除以2,(其实是建图的(二分图的所有顶点-最大匹配)/2  。化简一步才变成了:    复制一遍图之前的顶点(也就是原始图的顶点)- (最大匹配/2))题解如下:神奇啊二分图https://blog.csdn.net/mmy1996/article/details/52289564

但是最小路径覆盖的n都按照拆点之前的算。。。。

无向二分图的最小边覆盖 = 顶点数 – 最大二分匹配数/2

顶点数:就是用于构造无向二分图的城市数,即*的数量

最大二分匹配书之所以要除以2,是因为无向图匹配是双向的,因此除以2得到原图的真正的匹配数

AC代码:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;const int MAX = 505;
int n,m,tot;
bool line[MAX][MAX],used[MAX];
int nxt[MAX],vis[MAX][MAX];
char maze[MAX][MAX];
bool find(int x) {for(int i = 1; i<=tot; i++) {if(line[x][i] && used[i] == 0) {used[i] = 1;if(nxt[i] == -1 || find(nxt[i])) {nxt[i] = x;return 1;}}}return 0 ;
}
int match() {int sum = 0;memset(nxt,-1,sizeof nxt);for(int i = 1; i<=tot; i++) {memset(used,0,sizeof used);if(find(i)) sum++;}return sum;
}
int main()
{int t;cin>>t;while(t--) {tot=0;scanf("%d%d",&n,&m);//n行m列memset(line,0,sizeof line);memset(vis,0,sizeof vis);for(int i = 1; i<=n; i++) scanf("%s",maze[i]+1);for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '*') vis[i][j] = ++tot;}} for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == '*') {if(i-1 >= 1 && maze[i-1][j] == '*') line[vis[i][j]][vis[i-1][j]]=1;if(i+1 <= n && maze[i+1][j] == '*') line[vis[i][j]][vis[i+1][j]]=1;if(j-1 >= 1 && maze[i][j-1] == '*') line[vis[i][j]][vis[i][j-1]]=1;if(j+1 <= m && maze[i][j+1] == '*') line[vis[i][j]][vis[i][j+1]]=1;}}}printf("%d\n",tot - (match()/2));}return 0 ;} 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440347.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机教室安全预案 博客,校园安全应急预案

校园安全应急预案为了确保师生的人身安全&#xff0c;严格执行上级安全工作的管理要求&#xff0c;保证一旦发生安全事故能够及时处理&#xff0c;特制定我校安全应急预案。一、领导小组组 长&#xff1a;副组长&#xff1a;成 员&#xff1a;全体教师二、主要职责1、组长任校…

4.Model Validation

你已经建立了一个模型。 但它有多好&#xff1f; 在本课程中&#xff0c;您将学习如何使用模型验证来衡量模型的质量。 测量模型质量是迭代改进模型的关键。 What is Model Validation 你几乎要评估你构建的每个模型。在大多数&#xff08;尽管不是全部&#xff09;应用中&am…

【POJ - 2195】Going Home(二分图最优匹配,费用流 或 KM)

题干&#xff1a; On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step h…

微机原理实验8254计算机钢琴,GitHub - SincereXIA/PianoMFC: 西电微机原理课设项目,键盘电子乐器演奏程序设计(电子琴),MFC...

PianoMFC西电微机原理课设项目&#xff0c;键盘电子乐器演奏程序设计(电子琴)&#xff0c;MFC需要连接西电微机原理实验室提供的 QTH9054 微机试验箱&#xff0c;使用其蜂鸣器发声&#xff0c;若不连接&#xff0c;程序会直接播放 mp3 文件模拟钢琴声。请在 release 处下载编译…

5.Underfitting and Overfitting

在这一步结束时&#xff0c;您将了解欠拟合和过拟合的概念&#xff0c;并且您将能够应用这些办法来使您的模型更准确。 Experimenting With Different Models 现在您已经有了一种可靠的方法来测量模型精度&#xff0c;您可以尝试使用其他模型&#xff0c;并查看哪种模型可以提…

福建省计算机初级职称,2019福建助理工程师职称评定条件材料及审核管理制度...

一学历、资历条件要求(破格申报不在此列&#xff0c;详情请咨询了解)申报工程技术系列中级工程师须符合下列条件之一&#xff1a;1.博士研究生毕业&#xff1b;2.硕士研究生毕业后&#xff0c;从事所申报专业工作满3年&#xff1b;3.本科毕业后&#xff0c;从事所申报专业工作满…

【POJ - 2594】Treasure Exploration(floyd传递闭包 + 最小路径覆盖,图论)

题干&#xff1a; Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings…

6.Random Forests

Introduction 决策树会让您做出艰难的决定。 有很多树叶的深树将会过拟合&#xff0c;因为每个预测都来自其叶子上只有少数房屋的历史数据。 但是叶子很少的浅树会表现不佳&#xff0c;因为它无法捕获原始数据中的许多区别。 即使在今天&#xff0c;最成熟的建模技术也面临着过…

7.Handling Missing Values

本教程是学习机器学习课程的第2部分。 本教程选择了1级完成的位置&#xff0c;因此如果您从1级完成练习&#xff0c;您将获得最大的收益。 在此步骤中&#xff0c;您将学习三种处理缺失值的方法。 然后&#xff0c;您将学习如何比较这些方法在任何给定数据集上的有效性。 Intr…

打开电脑计算机超级慢,手把手教你电脑开机慢怎么办

等到花都谢了&#xff0c;你怎么还不开机&#xff1f;这电脑开机真是离奇的慢&#xff0c;有心将它换了&#xff0c;奈何兜里空空。凑合着用又无法忍受这种煎熬。其实你只需要用鼠标点几下就可以不用等待这漫长的开机过程了。高铁&#xff0c;飞机&#xff0c;网络&#xff0c;…

【POJ - 1486】Sorting Slides(思维建图,二分图求必须边,关建边,图论)

题干&#xff1a; Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minima…

用OpenSSL编写SSL,TLS程序

http://zhoulifa.bokee.com/6134045.html http://blog.sina.com.cn/s/blog_86ca13bb0100vaph.html http://blog.chinaunix.net/uid-26575352-id-3048856.html 一、简介: SSL(SecureSocket Layer)是netscape公司提出的主要用于web的安全通信标准,分为2.0版和3.0版.TLS(Transport…

信息技术计算机伦理与安全教案,龙教版信息技术七年级下册第7课 安全与道德 教案...

ID:9954219分类&#xff1a;全国,2019资源大小&#xff1a;228KB资料简介:题 目第七课 安全与道德总课时1设计来源自我设计教学时间教材分析这节课计算机与网络安全部分定义介绍和叙述较多,所以为了避免枯燥可以设计课件和并准备病毒计算机安全报道的视频、多媒体讲解、图片等…

【HDU - 5706】GirlCat(bfs)

题干&#xff1a; As a cute girl, Kotori likes playing Hide and Seek with cats particularly. Under the influence of Kotori, many girls and cats are playing Hide and Seek together. Koroti shots a photo. The size of this photo is nmnm, each pixel of the ph…

8.Using Categorical Data with One Hot Encoding

本教程是机器学习系列的一部分。 在此步骤中&#xff0c;您将了解“分类”变量是什么&#xff0c;以及处理此类数据的最常用方法。 Introduction 分类数据是仅采用有限数量值的数据。 例如&#xff0c;如果人们回答一项关于他们拥有哪种品牌汽车的调查&#xff0c;结果将是明…

iPhone换屏幕测试软件,怎样检验iPhone是否更换过屏幕?

原标题&#xff1a;怎样检验iPhone是否更换过屏幕&#xff1f;关注下图公众号&#xff0c;鉴定苹果手机真假↓↓↓购买新手机时&#xff0c;到手后会想手机各零部件是否是正品原装&#xff0c;就好比屏幕是否原装屏&#xff01;入手一部iPhone新机的时候&#xff0c;该如何检验…

*【HDU - 5707】Combine String(dp)

题干&#xff1a; Given three strings aa, bb and cc, your mission is to check whether cc is the combine string of aa and bb. A string cc is said to be the combine string of aa and bb if and only if cc can be broken into two subsequences, when you read the…

《TCP/IP详解》学习笔记(一):基本概念

为什么会有TCP/IP协议 在世界上各地&#xff0c;各种各样的电脑运行着各自不同的操作系统为大家服务&#xff0c;这些电脑在表达同一种信息的时候所使用的方法是千差万别。就好像圣经中上帝打乱 了各地人的口音&#xff0c;让他们无法合作一样。计算机使用者意识到&#xff0c;…

【POJ - 3272】Cow Traffic(dp,建反向图,DAG拓扑图)

题干&#xff1a; The bovine population boom down on the farm has caused serious congestion on the cow trails leading to the barn. Farmer John has decided to conduct a study to find the bottlenecks in order to relieve the traffic jams at milking time. The…

pc服务器不同型号,服务器与PC系统软件之不同

服务器与PC系统软件之不同对于中关村在线的网友来说&#xff0c;PC系统应该都不陌生&#xff0c;而且分分钟重装的水准。但在笔者过往的服务器装机经验中&#xff0c;可谓是一部千年血泪史。服务器和PC系统差别还是很大的。现在的PC系统多是windows7和windows10&#xff0c;而在…