热门标签 | 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中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 实体映射最强工具类:MapStruct真香 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 2023年京东Android面试真题解析与经验分享
    本文由一位拥有6年Android开发经验的工程师撰写,详细解析了京东面试中常见的技术问题。涵盖引用传递、Handler机制、ListView优化、多线程控制及ANR处理等核心知识点。 ... [详细]
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 深入解析 Apache Shiro 安全框架架构
    本文详细介绍了 Apache Shiro,一个强大且灵活的开源安全框架。Shiro 专注于简化身份验证、授权、会话管理和加密等复杂的安全操作,使开发者能够更轻松地保护应用程序。其核心目标是提供易于使用和理解的API,同时确保高度的安全性和灵活性。 ... [详细]
  • 探讨一个显示数字的故障计算器,它支持两种操作:将当前数字乘以2或减去1。本文将详细介绍如何用最少的操作次数将初始值X转换为目标值Y。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • Android 渐变圆环加载控件实现
    本文介绍了如何在 Android 中创建一个自定义的渐变圆环加载控件,该控件已在多个知名应用中使用。我们将详细探讨其工作原理和实现方法。 ... [详细]
  • 本文探讨了领域驱动设计(DDD)的核心概念、应用场景及其实现方式,详细介绍了其在企业级软件开发中的优势和挑战。通过对比事务脚本与领域模型,展示了DDD如何提升系统的可维护性和扩展性。 ... [详细]
  • 深入了解 Windows 窗体中的 SplitContainer 控件
    SplitContainer 控件是 Windows 窗体中的一种复合控件,由两个可调整大小的面板和一个可移动的拆分条组成。本文将详细介绍其功能、属性以及如何通过编程方式创建复杂的用户界面。 ... [详细]
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社区 版权所有