热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

图论trainningpart1F.Highways

F.HighwaysTimeLimit:1000msMemoryLimit:靓丽的砖头64-bitintegerIOforma


f.highways time limit 33601000 msmemorylimit 3360漂亮的砖头64-bitintegerioformat : % lldjavaclassname 3360 maintheislandnationonofsatate y, sldmnhasaverypoorsystemofpublichighways.thesldmnngovernmentisawareofthisproblemandhasalreadyconstructedanumberofhighwaysconconononays rtanttowns.However,therearestillsometownsthatyoucan ' treachviaahighway.itisnecessarytobuildmorehighwayssothatitwilbepoucan


sldmntownsarenumberedfrom1tonandtownihasapositiongivenbythecartesiancoordinates (Xi, yi ).eachighwayconnectsexacltytwotowns.all highways (boththeoriginalonesandtheonesthataretobebuilt ) folllow straight lines ays esiandistancebetweentowns.allhighwayscanbeusedinbothdirections.highwayscanfreelycrosseachotth butadrivercanonlyswitchbetwetwethbetwetwethbetwetwethetwetwetetwethbetwetwetwetet


thesldmnngovernmentwantstominimizethecostofbuildingnewhighways.however, theywanttoguaranteethateverytownishighway-reachablefromeveryothertown.sincesldmnissoflat,thecostofahighwayisalwaysproporat theleastexpensivehighwaysystemwillbetheonethatminimizesthetotalhighwal


inputtheinputconsistsoftwoparts.thefirstpartdescribesalltownsinthecountry,andthesecondpartdescribesallofthehighwaysthathavave


thefirstlineoftheinputfilecontainsasingleintegern (1=n=750 ),representingthenumberoftowns.thenextnlineseachcontaintwow xiandyiseparatedbyaspace.thesevaluesgivethecoordinatesofithtown (for ifrom1ton ).coordinateswillhaveanabsolutevaluenogreatesogreated


thenextlinecontainsasingleintegerm (0=m=1000 ), representingthenumberofexistinghighways.thenextmlineseachcontainapairofintegersseparatedbyaspace.thesetwointegersgiveapapair onnectedbyahighway.eachpairoftownsisconnectedbyatmostonehighway。


outputwritetotheoutputasinglelineforeachnewhighwaythatshouldbebuiltinordertoconnectalltownswithminimalposssibletotalllllengthof new ldbepresentedbyprintingtownnumbersthatthishighwayconnects,separated by a space。


ifnonewhighwaysneedtobebuilt (alltownsarealreadyconnected ),theoutputfileshouldbecreatedbutitshouldbeeempty。


sample input 91500324551045212533139712 sample output 163749578


解决问题:找到最小生成树的父节点。 。


1 # include iostream2# include cstdio3# include cstring4# include cmath5# include algorithm6# include climits7# include vector 8 include string 11 # includeset 12 # definelllonglong 13 # define INF0x3F3 f14 usingnamespacestd 15 const int maxn=800; 16 int mp[maxn腼腆的故事maxn] 17 struct pos {18 int x,y; 19 ) p[maxn]; 20 int n,m,d[maxn],pre[maxn]; 1intdis(constposa,const pos b ) 22返回(a.x-b.x ) ) a.x-b.x ) ) a.y-b.y ) ) a.y-b.y ); 23 ) 24voidprim(intsrc ) {25 int i,j,index,theMin; 26for(I=1; i=n; I({27pre[I]=src; 28 d[i]=mp[src腼腆故事i] 29 ) 30pre[src]=-1; 31for(I=1; i n; I ) {32 theMin=INF; 33索引=-1; 34for(j=1; j=n; j ) 35if(pre[j]!=-1d [ j ] them in (them in=d [ index=j ]; 36 ) 37if(themin!=0) printf('%d%d(n ),index,pre[index] ); 38 pre[index]=-1; 39for(j=1; j=n; j () 40if(pre[j]!=-1d [ j ] MP [索引腼腆故事j ] ({ 41d [ j ]=MP [索引腼腆故事j ] 42 pre [ j ]=索引; 43(45 ) 46 ) 47intmain ) ) {48 int i,j,u,v; 49Scanf('%d ',n ); 50for(I=1; i=n; I )扫描(' % d % d )、p[i].x、p[i].y ); 51for(I=1; i=n; I ) 52for(j=I1; j=n; j ) 53 mp[i腼腆故事j]=mp[j腼腆故事I]=dis(p[I],p[j]; 54 ) 55扫描(' % d ',m ); 56while(m-- ) 57scanf ) ' %d%d ',u,v ); 58 mp[u腼腆故事v]=mp[v腼腆故事u]=0; 59 ) 60prim(1; 61返回0; 62 )视图代码


推荐阅读
  • java布尔字段用is前缀_POJO类中布尔类型的变量都不要加is前缀详解
    前言对应阿里巴巴开发手册第一章的命名风格的第八条。【强制】POJO类中布尔类型的变量都不要加is前缀,否则部分框架解析会引起序列化错误。反例:定义为基本 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • Python基础知识:注释、输出和input交互
    本文介绍了Python基础知识,包括注释的使用、输出函数print的用法以及input函数的交互功能。其中涉及到字符串和整数的类型转换等内容。 ... [详细]
  • 获取时间的函数js代码,js获取时区代码
    本文目录一览:1、js获取服务器时间(动态)2 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 也就是|小窗_卷积的特征提取与参数计算
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了卷积的特征提取与参数计算相关的知识,希望对你有一定的参考价值。Dense和Conv2D根本区别在于,Den ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文讨论了Kotlin中扩展函数的一些惯用用法以及其合理性。作者认为在某些情况下,定义扩展函数没有意义,但官方的编码约定支持这种方式。文章还介绍了在类之外定义扩展函数的具体用法,并讨论了避免使用扩展函数的边缘情况。作者提出了对于扩展函数的合理性的质疑,并给出了自己的反驳。最后,文章强调了在编写Kotlin代码时可以自由地使用扩展函数的重要性。 ... [详细]
  • 这篇文章主要介绍了Python拼接字符串的七种方式,包括使用%、format()、join()、f-string等方法。每种方法都有其特点和限制,通过本文的介绍可以帮助读者更好地理解和运用字符串拼接的技巧。 ... [详细]
  • SQL Server 2008 到底需要使用哪些端口?
    SQLServer2008到底需要使用哪些端口?-下面就来介绍下SQLServer2008中使用的端口有哪些:  首先,最常用最常见的就是1433端口。这个是数据库引擎的端口,如果 ... [详细]
  • k8s进阶之搭建私有镜像仓库
    企业级私有镜像仓 ... [详细]
author-avatar
手机用户美佛_885
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有