



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Problem one: TrainsThe local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of the tracks are one-way. That is, a route from Kaitaia to Invercargill does not imply the existence of a route from Invercargill to Kaitaia. In fact, even if both of these routes do happen to exist, they are distinct and are not necessarily the same distance!The purpose of this problem is to help the railroad provide its customers with information about the routes. In particular, you will compute the distance along a certain route, the number of different routes between two towns, and the shortest route between two towns.Input: A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town.Output: For test input 1 through 5, if no such route exists, output NO SUCH ROUTE. Otherwise, follow the route as given; do not make any extra stops! For example, the first problem means to start at city A, then travel directly to city B (a distance of 5), then directly to city C (a distance of 4).1. The distance of the route A-B-C.2. The distance of the route A-D.3. The distance of the route A-D-C.4. The distance of the route A-E-B-C-D.5. The distance of the route A-E-D./算法1, 用于查表计算6. The number of trips starting at C and ending at C with a maximum of 3 stops. In the sample data below, there are two such trips: C-D-C (2 stops). and C-E-B-C (3 stops).7. The number of trips starting at A and ending at C with exactly 4 stops. In the sample data below, there are three such trips: A to C (via B,C,D); A to C (via D,C,D); and A to C (via D,E,B)./算法2,只计算边的条数,使用dfs解决8. The length of the shortest route (in terms of distance to travel) from A to C. /使用经典的最短路径解决9. The length of the shortest route (in terms of distance to travel) from B to B.10. number of different routes from C to C with a distance of less than 30. In the sample data, the trips are: CDC, CEBC, CEBCDC, CDCEBC, CDEBC, CEBCEBC, CEBCEBCEBC./某个范围内的路径数,。使用dfs解决Test Input:For the test input, the towns are named using the first few letters of the alphabet from A to D. A route between two towns (A to B) with a distance of 5 is represented as AB5.Graph: AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7Expected Output:Output #1: 9Output #2: 5Output #3: 13Output #4: 22Output #5: NO SUCH ROUTEOutput #6: 2Output #7: 3Output #8: 9Output #9: 9Output #10: 7设计方案一、 总体设计分类实现单向图数据输入规则N输入规则1输入规则1结果二、详细设计将以上10个问题,归纳总结为4种问题:1. 15 为一类问题解决思路:将Graph: AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7 转为邻接矩阵, 读取相应的权值相加即可。行名代表:from, 列名:to。 -1:没路 ,正数:权值。 例如:A,B,5B,C,4C,D,8D,C,8D,E,6A,D,5C,E,2E,B,3A,E,7ABCDEA-15-157B-1-14-1-1C-1-1-182D-1-18-16E-13-1-1-1转化2. 6,7,10 为一类问题解决思路:1使用DFS(深度优先搜索),2细节上对于6问题,从起点到终点,经历的路线数是小于等于某个值。对于问题7,从起点到终点,经历的路线数是等于某个值。对于问题10,从起点到终点,经历的路线数是小于某个值。6,7每走一条路,累加路的条数,10为累加路的权值。DFS 的设计:以7问为例public void dfs(GraphData data, int maxstops, int tn, int fn, int curstops)/1.递归的出口if(curstops maxstops)return;if(curstops = maxstops)if(fn = tn)System.out.println(log);equalWay+;return;/2.递归遍历到达结点for(int i = 0; i data.getLength(); +i)if(data.getEdge(fn, i) 0)continue;log.add(i);dfs(data, maxstops, tn, i, curstops+1);log.remove(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中风病中医护理查房
- 健康知识讲座培训提纲课件
- 侵袭性胸腺瘤CT课件
- 3 岁以下婴幼儿回应性照护指南
- 矿产信息公示管理办法
- 网络域名管理办法细则
- 网络信息推送管理办法
- 宇宙膨胀与暗物质的潜在关联-洞察及研究
- 导游证考试复习资料:全国导游基础知识(第10版)(2025北京市)
- 2025年中央一号文件知识考试题附答案
- 五年级美术素养测评模拟测试
- 销售流程与管理制度
- 外墙刷漆施工安全协议书
- 衡阳市物业服务收费管理实施细则
- 灾后重建生态修复建设林草植被恢复项目实施方案
- 《零售基础》完整课件(共六章节)
- 八年级心理健康教育课件
- 2025-2030中国除尘设备行业市场发展分析及前景趋势与投资研究报告
- 开学第一课校园防骗课件(小学生)
- 《华为存储产品介绍》课件
- DB33T 1197-2020 建筑地基基础工程施工质量验收检查用表标准
评论
0/150
提交评论