首页 > 其他分享 >COMP9021 Principles of Programming Coding Quiz 5

COMP9021 Principles of Programming Coding Quiz 5

时间:2024-07-18 09:18:20浏览次数:11  
标签:stair Coding Programming Quiz step steps grid stairs size

 

COMP9021 Principles of Programming

Term 2, 2024

Coding Quiz 5

Worth 4 marks and due Week 8 Thursday @ 9pm

Description

You are provided with a stub in which you need to insert your code where indicated without doing any

changes to the existing code to complete the task. Although it is not needed for this quiz, you may import

any extra module that is already installed in Ed if you wish.

The program randomly generates a grid with 0s and 1s, whose dimension is controlled by user input, as

well as the density of 1s in the grid, and finds out for a given step_number 1 and a given step_size 2,

the number of stairs of step_number many steps, with all steps of size step_size.

A stair of 1 step of size 2 is of the form:

1 1

1 1

A stair of 2 steps of size 2 is of the form

1 1

1 1

1 1

A stair of 1 step of size 3 is of the form

1 1 1

1

1 1 1

A stair of 2 steps of size 3 is of the form

1 1 1

1

1 1 1

1

1 1 12

The output lists the number of stairs from smallest step sizes to largest step sizes, and for a given step size,

from stairs with the smallest number of steps to stairs with the largest number of stairs.

Your task is to implement the function called stairs_in_grid().

You may possibly define other functions.

The provided stub and the outputs of the sample test cases explain the task to be performed.

Marking

stairs_in_grid() 4 marks

------------------------------------

Total

4 marks

Due Date and Submission

Quiz 5 is due Week 8 Thursday 18 July 2024 @ 9.00pm (Sydney time).

Note that late submission with 5% penalty per day is allowed up to 3 days from the due date, that is, any

late submission after Week 8 Sunday 21 July 2024 @ 9pm will be discarded.

Make sure not to change the filename quiz_5.py while submitting by clicking on [Mark] button in Ed.

It is your responsibility to check that your submission did go through properly using Submissions link in Ed

otherwise your mark will be zero for Quiz 5.3

Test Cases

$

python quiz_5.py

Enter three positive integers: 0 1 2

Here is the grid that has been generated:

1 1

0 1

$ python quiz_5.py

Enter three positive integers: 0 1 3

Here is the grid that has been generated:

1 1 0

1 1 1

1 1 1

For steps of size 2, we have:

2 stairs with 1 step

$ python quiz_5.py

Enter three positive integers: 0 3 9

Here is the grid that has been generated:

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

For steps of size 2, we have:

5 stairs with 1 step

1 stair with 2 steps

1 stair with 3 steps

1 stair with 4 steps

For steps of size 3, we have:

4 stairs with 1 step

4

$ python quiz_5.py

Enter three positive integers: 0 3 7

Here is the grid that has been generated:

1 1 0 1 1 1 1

1 1 1 1 1 1 0

1 1 1 0 0 1 1

0 1 1 1 1 1 1

1 0 0 0 1 0 1

1 1 1 0 1 1 1

1 1 0 0 1 1 0

For steps of size 2, we have:

2 stairs with 1 step

2 stairs with 2 steps

For steps of size 3, we have:

1 stair with 2 steps

$ python quiz_5.py

Enter three positive integers: 0 4 8

Here is the grid that has been generated:

1 1 0 1 1 1 1 1

1 1 1 1 1 1 1 1

0 1 1 1 1 1 1 0

0 1 1 1 0 1 1 1

1 1 1 1 1 1 1 0

1 0 0 1 0 1 1 1

1 1 0 1 1 1 1 1

1 1 0 0 1 1 1 0

For steps of size 2, we have:

7 stairs with 1 step

3 stairs with 2 steps

2 stairs with 3 steps

For steps of size 3, we have:

2 stairs with 1 step

1 stair with 2 steps

For steps of size 4, we have:

1 stair with 1 step

5

$ python quiz_5.py

Enter three positive integers: 0 5 9

Here is the grid that has been generated:

1 1 0 1 1 1 1 1 1

1 1 1 1 1 1 1 0 1

1 1 1 1 1 1 0 1 0

1 1 1 1 0 1 1 1 1

1 1 1 1 1 1 1 0 1

0 0 1 1 1 1 1 0 1

1 1 1 1 1 1 0 1 1

1 1 1 1 1 0 0 1 1

1 0 1 1 1 1 0 1 1

For steps of size 2, we have:

4 stairs with 1 step

5 stairs with 2 steps

1 stair with 3 steps

2 stairs with 4 steps

For steps of size 3, we have:

9 stairs with 1 step

For steps of size 4, we have:

2 stairs with 1 step6

Some Test Cases Explained

$ python quiz_5.py

Enter three positive integers: 0 1 3

Here is the grid that has been generated:

1 1 0

1 1 1

1 1 1

For steps of size 2, we have:

2 stairs with 1 step

1 1

1 0

1 1

1 1 1

1 1 0

1 1

1 1

1 1

7

$ python quiz_5.py

Enter three positive integers: 0 3 9

Here is the grid that has been generated:

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

For steps of size 2, we have:

5 stairs with 1 step

1 1

0 1

1 1 1

1 1

1

1 1 1

0 1 1

1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1

0

0

1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1

0 1 1 0

1 1 1 1 1 1

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0

1 1

0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

1 stair with 2 steps

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1

1 1

0 1 1 0 1 1 0

1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

8

1 stair with 3 steps

1 1 0 1 1 1 1 1 1

1 1 1 1 0

1 1

0 1 1 0 1 1 1 0

1 1

1 1 0 0 0 1 0 1

1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

1 stair with 4 steps

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0

1 1

0 1 1

1 1 0 1 1

1 1

1 1

1 0 1 1 0 0

1 1

0 1 1 1 1 1 1 0

1 1

For steps of size 3, we have:

4 stairs with 1 step

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

1 1 0 1 1 1 1 1 1

1 1 1 1 0 1 1 1 0

0 1 1 0 1 1 1 1 1

1 1 0 0 0 1 0 1 1

1 1 0 1 1 1 1 1 0

0 1 1 0 1 1 0 1 1

1 1 0 1 1 1 1 1 1

1 0 1 1 0 0 1 1 0

0 1 1 1 1 1 1 1 1

标签:stair,Coding,Programming,Quiz,step,steps,grid,stairs,size
From: https://www.cnblogs.com/qq-99515681/p/18308729

相关文章

  • The 2022 ICPC Polish Collegiate Programming Contest (AMPPZ 2022)
    Preface今天由于是我们队搬毒瘤场,因此下午就不用集中训练索性继续VPUCup这场题很有外国场的风格,代码量和科技含量都不大,只要动动脑筋就行了,最后也是刚好打到了10题下班A.Aliases不难发现假设\(a=b=0\),则\(c\le\log_{10}n\le7\),因此只要考虑\(a+b+c\le7\)的情况,......
  • 【绝命Coding助力秋招】Python实现<实习僧>海投脚本
     hellohello~,这里是绝命Coding——老白~......
  • Toyota Programming Contest 2024#7(AtCoder Beginner Contest 362)
    ⚪题和板题大赛/jk好像能切的样子,但是太菜了,唐了8罚。A-BuyaPen输出除去某个颜色以外,其他颜色代表的最大值。点击查看代码#include<bits/stdc++.h>usingnamespacestd;inta,b,c;strings;signedmain(){cin>>a>>b>>c;cin>>s;if(s[0]=='R')a=103......
  • 2023 Henan Provincial Collegiate Programming Contest
    和零时加的队友打了一下,计算几何摆了,最优化摆了,adhoc摆了。A.小水獭游河南枚举前缀,是\(O(|\Sigma|)\)的,然后判断一下是不是回文串即可。B.ArtforRest昨天才做过这个套路的加强版。显然只用判断类似\(\max(a,b)<\min(b+1,c)\)的条件。暴力枚举是调和级数的。C.Toxel......
  • Toyota Programming Contest 2024#7(AtCoder Beginner Contest 362)
    这场比赛还是比较水的A,B,C跳过D题dij把点权和边权都转换为边权即可E题DP可以用\(map\)存一下等差数列的差先说\(O(n^4)\),\(f_{len,i,j,t}\)分别表示长度,现在在\(i\),上一个在\(j\)显然动态转移方程就有了\(f_{len,i,j,k}=\sum_{k=1}^{k=j-1}f_{len-1,j,k,t}\)点击查看......
  • 使用Java9 Flow API进行Reactive Programming
    importjava.util.concurrent.Flow;importjava.util.concurrent.Flow.Publisher;importjava.util.concurrent.Flow.Subscriber;publicclassReactiveExample{publicstaticvoidmain(String[]args){//创建一个发布者,发布一系列的数字Publisher......
  • Warnings for C programming
    WarningsforCprogramming"Undetectablenullbugs"fromdeadbytes:Thefollowingcodeshowsanexampleofavariabledeclaredbutnotsettoavalue.Insteadofreturningthefamiliar"null",itreturnswhatwasleftinthememoryu......
  • Denso Create Programming Contest 2024(AtCoder Beginner Contest 361)E-F
    E求一条树上的路径,使得走遍整棵树花费最小。我们容易发现树上的某条简单路径只需走一次,除此之外所有的路径都需要走两次,那么显而易见,我们需要求树的直径,之后将剩余的路径权值和乘二加上直径权值就可以。F数学题,对于数学题而言,个人感觉时间复杂度的计算对于题目的求解非常重......
  • 《Programming from the Ground Up》阅读笔记:p19-p48
    《ProgrammingfromtheGroundUp》学习第2天,p19-p48总结,总计30页。一、技术总结1.objectfilep20,Anobjectfileiscodethatisinthemachine'slanguage,buthasnotbeencompletelyputtogether。之前在很多地方都看到objectfile这个概念,但都没有看到起定义,这次......
  • Denso Create Programming Contest 2024(AtCoder Beginner Contest 361)
    DensoCreateProgrammingContest2024(AtCoderBeginnerContest361)\(A\)Insert\(AC\)循环结构。点击查看代码inta[200];intmain(){intn,k,x,i;cin>>n>>k>>x;for(i=1;i<=n;i++){cin>>a[i];cout......