题意:
使用python解决两个task,锻炼使用算法解决问题的能力
解析:
task1-partA:找到列表数字的峰值(峰值定义为大于其邻居的数字。一个峰值可能是列表中的第一个或最后一个数字,在这种情况下,它必须大于其唯一的邻居),首先判断列表首尾是否为峰值,lst[0]与lst[1]大小以及lst[n-2]和lst[n-1]的大小,其次判断中间数字和邻居数字的大小关系是否为峰值。
task1-partB:写一个函数power(n,p),它接受一个数和一个幂,并返回提升到给定幂的数。由于不能使用幂运算符,可将n连乘p次的结果,x=x*n,return x
task2-partA:根据嵌套列表作为邻接矩阵的图来显示路径大小,可根据路径列表先构造路线再根据邻接矩阵找到对应路径长度求和即可
task2-partB:寻找快速路径,根据路线矩阵返回路线图,路线图首尾为0,根据邻接矩阵图从0开始,选取最短路径,返回节点即可
涉及知识点:
列表,图的邻接矩阵,贪心算法
更多可加微信讨论
微信号:tiamo-0620
pdf全文
FIT1045 Algorithms and programming in Python, S2-2019
Assignment 2 (value 10%)
Due: Sunday 22nd September 2019, 11:55 pm.
Objectives
The objectives of this assignment are:
• To demonstrate the ability to implement algorithms using basic data structures and operations on them.
• To gain experience in designing an algorithm for a given problem description and implementing that
algorithm in Python.
• To demonstrate an understanding of complexity, and to the ability to implement algorithms of a given
complexity.
Submission Procedure
- Save your files into a zip file called yourStudentID yourFirstName yourLastName.zip
- Submit your zip file containing your solution to Moodle.
- Your assignment will not be accepted unless it is a readable zip file.
Important Note: Please ensure that you have read and understood the university’s policies on plagiarism
and collusion available at http://www.monash.edu.au/stud... You
will be required to agree to these policies when you submit your assignment.
A common mistake students make is to use Google to find solutions to the questions. Once you have seen a
solution it is often difficult to come up with your own version. The best way to avoid making this mistake is
to avoid using Google. You have been given all the tools you need in workshops. If you find you are stuck, feel
free to ask for assistance on Moodle, ensuring that you do not post your code.
Marks: This assignment will be marked both by the correctness of your code and by an interview with
your lab demonstrator,
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。