题意:

使用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开始,选取最短路径,返回节点即可

涉及知识点:

列表,图的邻接矩阵,贪心算法

更多可加微信讨论
微信: IT_51zuoyejun
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

  1. Save your files into a zip file called yourStudentID yourFirstName yourLastName.zip
  2. Submit your zip file containing your solution to Moodle.
  3. 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/students/policies/academic-integrity.html. 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, to assess your understanding. This means that although the quality of your code
    (commenting, decomposition, good variable names etc.) will not be marked directly, it will help to write clean
    code so that it is easier for you to understand and explain.
    This assignment has a total of 10 marks and contributes to 10% of your final mark. For each day an assignment
    is late, the maximum achievable mark is reduced by 10% of the total. For example, if the assignment is late by
    3 days (including weekends), the highest achievable mark is 70% of 10, which is 7. Assignments submitted 7
    days after the due date will normally not be accepted.
    Detailed marking guides can be found at the end of each task. Marks are subtracted when you are unable to
    explain your code via a code walk-through in the assessment interview. Readable code is the basis of a
    convincing code walk-through.
    Task 1: Complexity (4 Marks)
    Create a Python module called complexity.py. Within this module implement the following task. For this
    module you may not use the Python built-in function pow(x) and you may not use the power operator **.
    You may not import any other libraries or modules.
    Part A: Peaks (2 Marks)
    Sometimes in life we care more about finding peaks than we care about finding the maximum. For example,
    during semester you know that the week containing the maximum amount of assessment is (probably) during
    exam block. But you will also have weeks in which that particular week contains more assessment than the
    week directly before it, or directly after it. As such, if you are planning on going to the movies with friends,
    you should probably do it in a week that is not an assessment peak.
    Write a function local peak(lst) that takes in a list of numbers, and returns the index of a local peak.
    Input: a list lst containing two or more numbers, where no number is the same as its neighbour.
    Output: an integer indicating the index of a local peak. If there is more than one peak in the given list, the
    index of any peak may be returned. A peak is defined as a number that is greater than its neighbours. A
    peak may be the first or last number in the list, in which case it must be greater than its only neighbour.
    For full marks, this function must have a complexity of O(log(N)), where N is the length of lst. Be aware
    that some Python functions have a higher complexity than you might think. One example is slicing, which has
    a complexity of O(k) where k is the length of the slice.
    Examples
    a) Calling local peak([0,2,4,6,5,2]) returns 3.
    b) Calling local peak([-7,-6,-2,-10,-5,-11]) returns either 2 or 4.
    c) Calling local peak([8.8,8.6,8.1,8.2,8.1,8.01]) returns either 0 or 3.
    Part B: Powers (2 Marks)
    Write a function power(n, p) that takes a number and a power and returns the number raised to the given
    power.
    Input: a number n and a non-negative integer p.
    Output: a number that is the evaluation of np
    For full marks, this function must have a complexity of O(log§).
    Examples
    a) Calling power(2,8) returns 256.
    Marking Guide (total 4 marks)
    Marks are given for the correct behavior of the different functions:
    (a) 1 mark for the correct behaviour of local peak, and 1 mark for implementing the function with a complexity
    of O(log(N)). You must be able to explain why the function has a complexity of O(log(N)) to receive the
    full mark.
    (b) 1 mark for the correct behaviour of power, and 1 mark for implementing the function with a complexity
    of O(log§). You must be able to explain why the function has a complexity of O(log§) to receive the
    full mark.
    Note: marks will be deducted for including in submitted module function calls that are outside of function
    definitions, or print statements.
    Task 2: Birthday Card (6 Marks)
    Your good friend, Xanthe, who also lives in Melbourne, is turning 21 in a few weeks. To celebrate the occassion
    you would like to give Xanthe a birthday card that has been signed by all of her friends. The only problem is
    Xanthe is incredibly well travelled, and has friends all through the country and the world.
    To figure out the best way to get the card to all of these friends before Xanthe’s birthday, you have turned
    to graph theory. Every city and town in which a friend of Xanthe lives has been allocated a number between
    1 and the number of friends (minus one), and Melbourne has been allocated the number 0. You have recorded
    postage times between locations as edge weights. You have found that all pairs of locations are such that the
    postage time from A to B is the same as the postage time from B to A, so your graph is undirected. You have
    also found that there is a postage connection between every pair of locations, so your graph is connected and
    complete. You have implemented this graph as an adjacency matrix, where each cell represents the weight of
    an edge. All postage times are given in integers, representing how many days the card would take to travel
    between the two locations. (I.e. an edge weight of 2 between A and B means it would take two days to get the
    card between location A and location B.)
    Create a Python module called card.py. Within this module implement the following three tasks. You are
    encouraged to decompose the given tasks into additional functions. You may not import any other libraries or
    modules.
    Part A: Time (1 Mark)
    Write a function post time(graph, path) that returns how long it will take Xanthe’s card to travel the given
    path.
    Input: a nested list graph that represents a graph as an adjacency matrix, that models the postage routes
    and times between Xanthe’s friends; and a list of integers path that represents a proposed path in the
    graph. You may assume the given path exists in the graph.
    Output: an integer that is the number of days it would take Xanthe’s card to travel the given path.
    Examples
    postage1 =
    [ [0,1,1,3,2],
    [1,0,4,5,1],
    [1,4,0,1,3],
    [3,5,1,0,1],
    [2,1,3,1,0] ]
    postage2 =
    [ [0,2,2,1,2],
    [2,0,1,1,2],
    [2,1,0,1,4],
    [1,1,1,0,1],
    [2,2,4,1,0] ]
    The example graphs postage1 and postage2 are provided for illustrative purpose. Your implemented function
    must be able to handle arbitrary graphs in matrix form.
    a) Calling post time(postage1, [0,1,4,3,2,0]) returns 5.
    b) Calling post time(postage1, [0,3,1,2,3]) returns 13.
    Part B: Where to post? (2.5 Marks)
    Write a function post route(graph) that uses a greedy approach to find a fast (but not necessarily the fastest)
    route by which to send the card. The metric for the greedy approach is: send the card to the location that takes
    the shortest time to get to that the card has not yet been visited; or, if all locations have been visited, send the
    card back to Melbourne. If there are multiple locations to chose from, all with the same distance, choose the
    location that has been allocated the smaller number.
    Input: a nested list graph that represents a graph as an adjacency matrix, that models the postage routes
    and times between Xanthe’s friends.
    Output: a list of integers, where each integer is a location, ordered such that visiting each location in the
    order given creates a cycle that begins and ends in Melbourne. The only number that can appear twice is

Examples
a) Calling post route(postage1) returns [0,1,4,3,2,0].
b) Calling post route(postage2) returns [0,3,1,2,4,0].
Part C: Can it be done? (2.5 Marks)
Write a function on time(graph,days) that determines whether there exists a postage route that can be
completed before Xanthe’s birthday.
Input: a nested list graph that represents a graph as an adjacency matrix, that models the postage routes
and times between Xanthe’s friends; and a non-negative integer days, which is the number of days until
Xanthe’s birthday.
Output: a boolean, True if there exists a cycle beginning and ending at Melbourne, that visits every location,
and that has a weight equal or less than days; otherwise False.
You must cite any lecture code you use.
Examples
a) Calling on time(postage1,5) returns True, because there is a cycle in graph postage1 with weight ≤ 5
that fits the criteria: [0,1,4,3,2,0].
b) Calling on time(postage2,8) returns True, because there is a cycle in graph postage2 with weight ≤ 8
that fits the criteria: [0,1,2,3,4,0].
c) Calling on time(postage2,5) returns False, because there is no cycle in graph postage2 with weight ≤ 5
that fits the criteria.
Marking Guide (total 6 marks)
Marks are given for the correct behavior of the different functions:
(a) 1 mark for post time.
(b) 2.5 marks for post route.
© 2.5 marks for on time.
Note: marks will be deducted for including in submitted module function calls that are outside of function
definitions, or print statements.

莫纳什大学 FIT1045 assignment2课业解析相关推荐

  1. 莫纳什大学FIT1043 assignment2课业解析

    题意: 使用python来研究一个热带大气海洋数据集 解析: 任务A:分析数据集,查看数据集行与列的大小,每列中的最值,列出每个月的记录数,删除缺失值,可视化不同月份的海面温度,探索降水测量,调查每日 ...

  2. 未找到要求的 from 关键字_莫纳什大学要求

    莫纳什大学申请要求如下:1.商科方向学术985院校75%;211院校75%;非211院校75%.Master of Business 要求73%;Master of Professional Acco ...

  3. 莫纳什大学计算机专业在哪个校区,莫纳什大学校区几个

    澳大利亚莫纳什大学总共有八个校区,其中有六所皆设址于墨尔本附近,主校区位于墨尔本市东南区.具体的位置在:Wellington Rd, Clayton VIC 3800澳大利亚克莱敦校区(Clayton ...

  4. 莫纳什大学计算机专业排名,2020年莫纳什大学排名前五的专业有哪些

    莫纳什大学(Monash University),也称为蒙纳士大学.世界百强名校,是澳洲八大名校(Group of Eight)的盟校成员.于1958年由国会建立,是维多利亚州的第二所古老的大学.莫纳 ...

  5. 莫纳什大学计算机专业研究生在哪个校区,盘点莫纳什大学2019年计算机类硕士课程...

    莫纳什大学(Monash University),世界百强名校,澳大利亚名校联盟"八大名校"(Group of Eight)之一,五星级大学.1958年由国会建立,为纪念杰出的澳大 ...

  6. 莫纳什计算机专业优势,2020年去澳洲留学就读莫纳什大学计算机学院有哪些优势?...

    去澳洲留学就读莫纳什大学计算机学院有哪些优势? 阅读:117次 更新时间:2017-07-04 13:53:57 添加时间:2017-07-04 编辑:gouyuling 来源: 莫纳什大学 索取招生 ...

  7. 莫纳什大学计算机工程,莫纳什大学计算机系统工程专业本科.pdf

    莫纳什大学计算机系统工程专业本科.pdf 留学监理服务网 莫纳什大学 计算机系统工程 - Computer Systems Engineering 基本信息 莫 纳 什 大 学 - Monash 工程 ...

  8. 莫纳什大学招收AI/CV/ML/计算生物信息学和生物医学方向全奖博士研究生

    点击下方卡片,关注"CVer"公众号 AI/CV重磅干货,第一时间送达 Monash大学数据未来研究院招收模式识别,计算机视觉,计算生物信息学和生物医学方向全奖博士研究生 Mona ...

  9. 莫纳什大学计算机专业录取要求,2020年莫纳什大学计算机信息硕士申请条件

    莫纳什大学计算机信息硕士介绍 莫纳什大学的计算机课程由Faculty of Information Technology(信息技术学院)提供,在授课型计算机硕士课程方面,目前主要提供以下14个方向的专 ...

最新文章

  1. 肝了三天,万字长文教你玩转 tcpdump,从此抓包不用愁
  2. 周星驰的10个华人记录
  3. Excel:利用Excel内置功能实现对某列表格按照条件进行升降序排列
  4. openstack 管理三十五 - 利用 SQL 获取 tenant 当前资源情况
  5. github基本使用教程
  6. vue 监听浏览器页面关闭_前方高能,这是最新的一波Vue实战技巧,不用则已,一用惊人...
  7. SQL Serverver -- 创建财政年度表 (约束)
  8. 左手用R右手Python系列14——日期与时间处理
  9. mysql 外键 150_mysql之创建外键报150错误的处理方法
  10. EXCEL 根据超链接直接显示图片
  11. am解调matlab程序,AM调制解调的matlab仿真
  12. 基本农田卫星地图查询_天地图山东,购房者勘测利器,国产骄傲
  13. SUSE LINUX 10.1如何ADSL上网指南(转)
  14. vue之使用vue-video-player实现实时视频流播放
  15. 三明市机器人协会_☞ 智能之花 绚丽绽放——2019年三明市区首届青少年机器人竞赛活动在三明市陈景润实验小学完美收官...
  16. kaldi 语音识别 lattice-free MMI声学训练
  17. djay Pro 2 Mac(DJ混音软件) v2.0.11激活版
  18. 【转载】如何打领带-普瑞特结
  19. 密码必须包含字母大小写、数字、特殊字符,且不能少于8位
  20. [BZOJ3441] 乌鸦喝水

热门文章

  1. mysql 并发 链接失败_瞬发大量并发连接 造成MySQL连接不响应的分析
  2. Javaweb ajax实现分页
  3. 配音软件哪个好用?好用的配音软件有哪些?你不知道的3款配音软件
  4. win10系统 没有wifi图标 WiFi列表没有显示
  5. 热评云厂商:品高云4.62亿元,发力行业云,掘金实属不易
  6. 西雅图又一家科技公司准备上市!
  7. 利用opencv棋盘格标定法对鱼眼图像校正分析
  8. 【Dos】常见的Dos攻击
  9. nginx 过滤ip
  10. Go语言基础之网络编程