当前位置 |首页 > 作业代写 > Python代写 >
分享这个代写网站给同学或者朋友吧!

作业1

 

COMP9021,2018年第1次会议



 1.  一般事项

 

1.1。目标。这项任务的目的是:

 

让你设计解决简单问题的方案;

 

让你以短Python程序的形式实现这些解决方案;

 

练习使用算术计算,测试,重复,列表,元组,字典,deques,从文件中读取数据。

 

1.2。提交。您的节目将存储在多个文件中,每个文件只有一个文件名称。在您开发并测试您的程序后,请使用Ed上传您的文件。作业可以多次提交:最后一个版本被标记。您的任务将于4月15日晚上11:59分到期。

 

1.3。评定。4个练习中的每一个都值得2.5分。对于所有练习,自动标记脚本将让每个程序运行30秒。尽管如此,你仍然不应该利用这一点,并努力寻求一种能够为“合理”投入提供直接产出的解决方案。

 

迟到的作业将受到处罚:延迟提交的商标将是获奖商标的最低标准,并减去从到期日起已经过去的全部和部分日期的数量。

 

你的程序的输出应该完全按照指示。

 

1.4。提醒剽窃政策。你被允许,确实鼓励,讨论如何解决与其他人的任务。这种讨论必须根据算法而不是代码。但是你必须自己实施解决方案。通常会对提交内容进行扫描,以了解学生是否复制和修改其他人的工作,或者在单个实施中密切合作。严重处罚。


 2.  三角形

 

编写一个程序,存储在 名为triangle.py的文件中,执行以下任务。

 

程序提示用户输入一个文件名。如果在工作目录中没有该名称,那么该程序将输出(任意)错误消息并退出。

 

的文件的内容包括一些数量的行,每行是之前和RST和最后一个号码后由至少一个空间分开的,具有可能的空间整数的序列,分别为N个  具有正好线N号。例如,le triangle_1.txt 的内容 可以显示如下。

 

image.png

 

方案产出:

 

{最大值可以通过总结从三角形顶部开始的一条路径上的所有数字以及在每一级到倒数第二级的数值而得到的最大值下降到直接的左侧或右侧邻居;

 

{产生这个最大值的路径的数量; {最左边的这种路径,以列表的形式出现。

 

这是一个可能的互动:

 

$  cat triangle_1.txt

 

7

 

3 8

 

8 1 0

 

2 7 4 4

 

4 5 2 6 5

 

$  python3 triangle.py

 

你想使用哪个数据文件?triangle_1.txt  最大的总和是:30

 

产生这个总和的路径数量为:1

 

产生这个总和的最左边路径是:[7,3,8,7,5]

 

$  cat triangle_2.txt 1

 

2 2

 

1 2 1

 

2 1 1 2

 

1 2 1 2 1

 

2 1 2 2 1 2

 

$  python3 triangle.py

 

你想使用哪个数据文件?triangle_2.txt

 

最大的数额是:10

 

产生这个总和的路径数是:6

 

产生该和的最左边路径是:[1,2,1,2,2,2]

 

您可以假定任何测试文件的内容都符合预期,您不必检查它是否符合预期。


 3.  渔镇

 

编写一个存储在 名为fish.py 的程序,执行以下任务。

 

程序提示用户输入一个文件名。如果在工作目录中没有该名称,那么该程序将输出(任意)错误消息并退出。

 

le的内容由一些行组成,每行是由至少一个空格隔开的两个非负整数的序列,可能在第一个和第二个数之前和之后有空格,第一个列从第一行开始到形成严格递增序列的最后一行。第一个数字代表从海岸的一个点到更远的海岸的一个城镇的距离(以公里为单位)(所以城镇被列为好像我们从某个固定点沿着海岸行驶); 第二个数字代表该镇的绍勒人在当天凌晨捕获的sh数量(以千克表示)。例如,le coast_1.txt的内容 可以显示为

 


                   5   70


                 15  100 

 


                1200 20

         

这相当于我们有3个城镇,一个位于该点南部5公里处,另一个位于该点南部15公里处,第三个城镇位于该点南部1200公里处,其中70,100和20公斤sh是分别被那些镇的shermen抓住。

 

目的是通过可能将sh从一个城市运送到另一个城镇来最大化所有城镇(在所有城镇中相同)中sh的数量,但不幸的是每公里损失1公里sh。例如,如果决定从第二个城镇向第一个城镇发送20公斤sh,那么就是第二个城镇

 

最终有100 20 = 80公斤sh,而第一个最终有70 + 20(15 5)= 80公斤sh。

 

程序输出所有城镇可以有的sh的最大数量可能以最佳方式运输sh。

 

这是一个可能的互动:

 

$  cat coast_1.txt

 

5 70

 

15 100

 

1200 20

 

$  python3 fish.py

 

你想使用哪个数据文件?coast_1.txt

 

每个镇可以有的鱼的最大数量是20。

 

$  cat coast_2.txt 20 300 40 400 340 700 360 600

 

 

$  python3 fish.py

 

你想使用哪个数据文件?coast_2.txt

 

每个镇可以有的最大鱼量是415。

 

您可以假定任何测试文件的内容都符合预期,您不必检查它是否符合预期。


 4.  重叠的照片

 

编写一个程序,存储在 名为perimeter.py的文件中,执行以下任务。

 

提示用户输入假定要存储在工作目录中的文本的名称。我们假设如果这个名字是有效的,那么这个列由所有包含由空格分隔的4个整数的行构成,其形式为x 1  y 1  x 2  y 2  其中(x 1 ; y 1)和(x 2 ; y 2)是意在表示矩形的两个对角的坐标。使用提供的le frames_1.txt ,矩形可以表示如下,从上到下使用绿色,黄色,红色,蓝色,紫色,橄榄色和洋红色。

 

 

 image.png

我们假设所有的矩形都是不同的,要么恰当地重叠,要么是不相交的(它们彼此之间或者它们的一些角落都不相互接触)。

 

计算并输出边界的周长,因此使用样本le perimeter.py 计算下面图片(外部或内部)的长度总和。

 

 image.png

下面是两个提供的示例文件的程序示例运行 

 

$  python3 perimeter.py

 

 

$  python3 perimeter.py

 

你想使用哪个数据文件?frames_2.txt  外围是:9090


 5.  部分订单

 

编写一个程序,存储在 名为nonredundant.py的文件中,执行以下任务。

 

程序提示用户输入一个文件名。如果在工作目录中没有该名称,那么该程序将输出(任意)错误消息并退出。

 

文本的内容由R(m,n)形式的文本组成 其中 和 是整数(仅表示标签),分别在开始和结束括号之前和之后可能有空格。它表示一个偏序关系R(因此是一个不对称和传递的二元关系)。例如, 可以将partial_order_1.txt 的内容表示为:

 

 image.png

 

可以看出,两个事实是多余的:

 

{事实R(3; 1),从事实R(3; 5),R(5; 2)和R(2; 1); {事实R(4; 1),由事实R(4; 2)和R(2; 1)得出。

 

该程序输出非冗余的事实,尊重它们在文件中列出的顺序。

 

这是一个可能的互动:

 

$  cat partial_order_1.txt R(3,5)

 

R(4,2)

 

R(5,2)

 

R(2,1)

 

R(3,1)

 

R(4,1)

 

$  python3 nonredundant.py

 

你想使用哪个数据文件?partial_order_1.txt  非冗余事实是:

 

R(3,5)

 

R(4,2)

 

R(5,2)

 

R(2,1)


 

$  cat partial_order_2.txt R(3,5)

 

R(5,2)

 

R(2,6)

 

R(2,1)

 

R(3,6)

 

R(6,1)

 

R(4,2)

 

R(4,1)

 

$  python3 nonredundant.py

 

你想使用哪个数据文件?partial_order_2.txt  非冗余事实是:

 

R(3,5)

 

R(5,2)

 

R(2,6)

 

R(6,1)

 

R(4,2)

 

$  cat partial_order_3.txt R(1,2)

 

R(2,3)

 

R(3,4)

 

R(1,3)

 

R(2,4)

 

$  python3 nonredundant.py

 

你想使用哪个数据文件?partial_order_3.txt  非冗余事实是:

 

R(1,2)

 

R(2,3)

 

R(3,4)

 

您可以假定任何测试文件的内容都符合预期,您不必检查它是否符合预期。





Assignment 1

 

COMP9021, Session 1, 2018



 1. General matters

 

1.1. Aims. The purpose of the assignment is to:

 

let you design solutions to simple problems;

 

let you implement these solutions in the form of short Python programs;

 

practice the use of arithmetic computations, tests, repetitions, lists, tuples, dictionaries, deques, reading from les.

 

1.2. Submission. Your programs will be stored in a number of les, with one le per exercise, of the appropriate name. After you have developed and tested your programs, upload your les using Ed. Assignments can be submitted more than once: the last version is marked. Your assignment is due by April 15, 11:59pm.

 

1.3. Assessment. Each of the 4 exercises is worth 2.5 marks. For all exercises, the automarking script will let each of your programs run for 30 seconds. Still you should not take advantage of this and strive for a solution that gives an immediate output for \reasonable" inputs.

 

Late assignments will be penalised: the mark for a late submission will be the minimum of the awarded mark and 10 minus the number of full and partial days that have elapsed from the due date.

 

The outputs of your programs should be exactly as indicated.

 

1.4. Reminder on plagiarism policy. You are permitted, indeed encouraged, to discuss ways to solve the assignment with other people. Such discussions must be in terms of algorithms, not code. But you must implement the solution on your own. Submissions are routinely scanned for similarities that occur when students copy and modify other people's work, or work very closely together on a single implementation. Severe penalties apply.


 2. Triangle

 

Write a program, stored in a le named triangle.py, that performs the following task.

 

The program prompts the user to input a le name. If there is no le with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

 

The contents of the le consists of some number of lines, each line being a sequence of integers separated by at least one space, with possibly spaces before and after the rst and last number, respectively, the Nth line having exactly N numbers. For instance, the contents of the le triangle_1.txt can be displayed as follows.

 

image.png

 

The program outputs:

 

{ the largest value than can be obtained by summing up all numbers on a path that starts from the top of the triangle, and at every level down to the penultimate level, goes down to the immediate left or right neighbour;

 

{ the number of paths that yield this largest value; { the leftmost such path, in the form of a list.

 

Here is a possible interaction:

 

cat triangle_1.txt

 

7

 

3 8

 

8 1 0

 

2 7 4 4

 

4 5 2 6 5

 

python3 triangle.py

 

Which data file do you want to use? triangle_1.txt The largest sum is: 30

 

The number of paths yielding this sum is: 1

 

The leftmost path yielding this sum is: [7, 3, 8, 7, 5]

 

cat triangle_2.txt 1

 

2 2

 

1 2 1

 

2 1 1 2

 

1 2 1 2 1

 

2 1 2 2 1 2

 

python3 triangle.py

 

Which data file do you want to use? triangle_2.txt

 

The largest sum is: 10

 

The number of paths yielding this sum is: 6

 

The leftmost path yielding this sum is: [1, 2, 1, 2, 2, 2]

 

You can assume that the contents of any test le is as expected, you do not have to check that it is as expected.


 3. Fishing towns

 

Write a program, stored in a le named fish.py, that performs the following task.

 

The program prompts the user to input a le name. If there is no le with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

 

The contents of the le consists of some number of lines, each line being a sequence of two nonnegative integers separated by at least one space, with possibly spaces before and after the rst and second number, respectively, the rst numbers listed from the rst line to the last line forming a strictly increasing sequence. The rst number represents the distance (say in kilometres) from a point on the coast to a shing town further down the coast (so the towns are listed as if we were driving down the coast from some xed point); the second number represents the quantity (say in kilos) of sh that has been caught during the early hours of the day by that town's shermen. For instance, the contents of the le coast_1.txt can be displayed as

 


                   5  70


                 15  100

 


                1200 20

         

which corresponds to the case where we have 3 towns, one situated 5 km south the point, a second one situated 15 km south the point, and a third one situated 1200 km south the point, with 70, 100 and 20 kilos of sh being caught by those town's shermen, respectively.

 

The aim is to maximise the quantity of  sh available in all towns (the same in all towns) by possibly transporting  sh from one town to another one, but unfortunately losing 1 kilo of  sh per kilometre. For instance, if one decides to send 20 kilos of  sh from the second town to the  rst one, then the second town

 

ends up having 100 20 = 80 kilos of sh, whereas the rst one ends up having 70 + 20 (15 5) = 80 kilos of sh too.

 

The program outputs that maximum quantity of sh that all towns can have by possibly transporting sh in an optimal way.

 

Here is a possible interaction:

 

cat coast_1.txt

 

5 70

 

15 100

 

1200 20

 

python3 fish.py

 

Which data file do you want to use? coast_1.txt

 

The maximum quantity of fish that each town can have is 20.

 

cat coast_2.txt 20 300 40 400 340 700 360 600

 

 

python3 fish.py

 

Which data file do you want to use? coast_2.txt

 

The maximum quantity of fish that each town can have is 415.

 

You can assume that the contents of any test le is as expected, you do not have to check that it is as expected.


 4. Overlapping photographs

 

Write a program, stored in a le named perimeter.py, that performs the following task.

 

Prompts the user to input the name of text le assumed to be stored in the working directory. We assume that if the name is valid then the le consists of lines all containing 4 integers separated by whitespace, of the form x1 y1 x2 y2 where (x1; y1) and (x2; y2) are meant to represent the coordinates of two opposite corners of a rectangle. With the provided le frames_1.txt, the rectangles can be represented as follows, using from top bottom the colours green, yellow, red, blue, purple, olive, and magenta.

 

 

 image.png

We assume that all rectangles are distinct and either properly overlap or are disjoint (they do not touch each other by some of their sides or some of their corners).

 

Computes and outputs the perimeter of the boundary, so with the sample le perimeter.py, the sum of the lengths of the (external or internal) sides of the following picture.

 

 image.png

Here is a sample run of the program with the two provided sample les.

 

python3 perimeter.py

 

 

python3 perimeter.py

 

Which data file do you want to use? frames_2.txt The perimeter is: 9090


5

 5. Partial orders

 

Write a program, stored in a le named nonredundant.py, that performs the following task.

 

The program prompts the user to input a le name. If there is no le with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

 

The contents of the le consists of lines with text of the form R(m,n) where m and n are integers (that just represent labels), with possibly spaces before and after the opening and closing parentheses, respectively. It represents a partial order relation R (so an asymmetric and transitive binary relation). For instance, the contents of the le partial_order_1.txt can be represented as:

 

 image.png

 

It can be seen that two facts are redundant:

 

{ the fact R(3; 1), which follows from the facts R(3; 5), R(5; 2) and R(2; 1); { the fact R(4; 1), which follows from the facts R(4; 2) and R(2; 1).

 

The program outputs the facts that are nonredundant, respecting the order in which they are listed in the le.

 

Here is a possible interaction:

 

cat partial_order_1.txt R(3,5)

 

R(4,2)

 

R(5,2)

 

R(2,1)

 

R(3,1)

 

R(4,1)

 

python3 nonredundant.py

 

Which data file do you want to use? partial_order_1.txt The nonredundant facts are:

 

R(3,5)

 

R(4,2)

 

R(5,2)

 

R(2,1)


 

cat partial_order_2.txt R(3,5)

 

R(5,2)

 

R(2,6)

 

R(2,1)

 

R(3,6)

 

R(6,1)

 

R(4,2)

 

R(4,1)

 

python3 nonredundant.py

 

Which data file do you want to use? partial_order_2.txt The nonredundant facts are:

 

R(3,5)

 

R(5,2)

 

R(2,6)

 

R(6,1)

 

R(4,2)

 

cat partial_order_3.txt R(1,2)

 

R(2,3)

 

R(3,4)

 

R(1,3)

 

R(2,4)

 

python3 nonredundant.py

 

Which data file do you want to use? partial_order_3.txt The nonredundant facts are:

 

R(1,2)

 

R(2,3)

 

R(3,4)

 

You can assume that the contents of any test le is as expected, you do not have to check that it is as expected.

代写CS&Finance|建模|代码|系统|报告|考试

编程类:C++,JAVA ,数据库,WEB,Linux,Nodejs,JSP,Html,Prolog,Python,Haskell,hadoop算法,系统 机器学习

金融类统计,计量,风险投资,金融工程,R语言,Python语言,Matlab,建立模型,数据分析,数据处理

服务类:Lab/Assignment/Project/Course/Qzui/Midterm/Final/Exam/Test帮助代写代考辅导

E-mail:850190831@qq.com   微信:BadGeniuscs  工作时间:无休息工作日-早上8点到凌晨3点


如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。

qr.png


代写