CSE/UNSW/CISRA High Schools Programming Competition 2002

Preliminary Round, Open Competition

Instructions

This page contains links to all of the material needed to complete the Preliminary Round of the CSE/UNSW/CISRA High Schools Programming Competition.

The rules of the competition are given at http://do.cse.unsw.edu.au/progcomp/rules.html. Please read the rules carefully before commencing the competition.

In order to permit a wide range of languages to be used there are no strict requirements on the method of entering the test data or the method of displaying the results. You may supply your programs with the data in whichever way you wish.

Run each program on the test data provided. Print out the results of each run and submit these with the program listings.

The supervisor must sign the cover sheet and submit this together with all your printouts by express post mail. If possible please also submit an electronic copy to progcomp@cse.unsw.edu.au immediately after the competition. If you do not have access to email at your school the printed copy will be sufficient. Electronically submitted solutions will be marked more quickly.

Marks will be awarded for correct behaviour and for programming style. Good style involves simple clear programs with brief but informative comments.

Tasks may be completed in any order. You must stop working and submit your work so far after 2 hours. You can submit program listings, even if they're not working.

Advice to Competitors

We have provided a range of problems of varying difficulty: we expect that few teams will be able to complete all, or even most of the tasks. Do not be discouraged if you don't get many of them done. There is no pass mark, and even solving one problem is an achievement.

There are six tasks. Each task is worth 15 marks. Because you have to share a single computer you may that find the best strategy is to work on two or three tasks simultaneously (one or two people on each task). Credit will be given for all work done, so any partial attempts should be submitted.

There are also 5 bonus marks available for some tasks, but there is no partial credit for the bonus marks. Either all 5 marks will be awarded or nothing, so only try for the bonus marks if you are very sure you will complete them.

Good luck, and have fun!


Task 1 - Digital Roots

Description

The digital root of a number is the one digit sum of its digits.

For example the digital root of 24 is 6 (2+4=6).

If the sum has more than one digit then repeat the process over and over again until a single digit remains.

For example the digital root of 9299 is 2 (9+2+9+9=29, and 2+9=11, and 1+1=2)

You are to write a program which, given a non-negative integer, calculates and prints its digital root.

Examples

Sample InputSample Output
24 The digital root of 24 is 6
999 The digital root of 999 is 9

Test Data

24
999
9299
12345678
987987654321

Constraints

You may assume the number given is an integer between 0 and 1080 inclusive.


Task 2 - Amicable Numbers

Writing a program which determines whether a pair of numbers are amicable numbers. Amicable numbers are two numbers such that the sum of each one's positive factors (except for itself) equals the other number. The smallest known pair is 220 and 284.

For example, the factors of 220 are [1,2,4,5,10,11,20,22,44,55,110] which sum to 284, and the factors of 284 are [1,2,4,71,142] which sum to 220.

Examples:

Sample InputSample Output
100 200 100 and 200 are NOT amicable numbers
284 220 284 and 220 ARE amicable numbers

Test Data

100,200
284,220
2924,6232
5020,5564
12285,14595


Task 3 - Combinations

Description

Write a computer program to generate all the possible combinations of n letters, choosing from m letters. Your output should match the format of the sample output, i.e. each combination on a separate line.

The input is a pair of integers m and n. Print all combinations of n letters drawn from the first m letters of the alphabet.

Your output must not contain duplicate combinations. Note that combinations ignore order. For example: ABC is the same combination as CBA (even though the order is different).

Examples

Sample InputSample Output
4,2 AB
AC
AD
BC
BD
CD
7,7 ABCDEFG

Test Data

4,2
7,7
8,4
10,8

Constraints

You may assume that 0 < n <= m <= 26.


Bonus Marks

Bonus marks will be awarded for a constructive solution, i.e. one which internally only generates valid combinations (as opposed to a solution which has to at some point go through eliminating invalid/duplicate combinations).


Task 4 - Packing Weights

Description

You have a supply of weights, and you need to load them into paper bags for transportation. However, each bag can only carry 10 kg. Any more weight than this would break the bag. Given a list of weights (in kg), you will need to determine an 'optimal' arrangement for transporting the weights. An optimal arrangement uses the least number of bags possible.

Write a program which, given a list of weights, returns an optimal arrangement. Output must match that shown below (with each bag's contents listed on a separate line). You may list the bags in any order.

Examples

Sample InputSample Output
7,3,5 An optimal arrangement:
7,3
5
8,9,3,4,2 An optimal arrangement:
8,2
9
3,4

Test Data

7,3,5
8,9,3,4,2
1,1,1,1,1,1,1,1,1,1,1
6,5,2,2,2,3
7,6,2,2,3,1

Constraints

You may assume every number in the input is an integer and lies in the range 1 to 10 inclusive. You may assume no more than 25 weights will be given.


Bonus Marks

You will receive the bonus marks if you also find a most balanced optimal arrangement. This is an optimal arrangement such that the largest bag-weight is a minimum. (If there is more than one most balanced arrangement, you can return any of them)

Example

We are given weights 7, 3, and 5 kg. Clearly an optimal arrangement uses 2 bags. But we could have 7/3 in one bag and 5 in another, or 7 in one bag and 5/3 in the other. The most balanced arrangement is 7 in one bag and 5/3 in the other because then the largest weight of a bag is 8 kg, whereas 7/3 and 5 would give a largest weight of 10 kg.

Test Data

As above. But, if you attempt the bonus marks, use the wording "A most balanced optimal arrangement" instead of "An optimal arrangement".

Examples

Sample InputSample Output
7,3,5 A most balanced optimal arrangement:
7
5,3
8,9,3,4,2 A most balanced optimal arrangement:
8
9
2,3,4


Task 5 - Inside/Outside

Description

Write a program which, given a list of co-ordinates of the vertices of a convex polygon, and then some other point, determines whether or not that point is inside the polygon. Your output is to match that of the sample output.

A convex polygon is one such that from any vertex, you can see every other vertex (direct line of sight) without going outside the boundary of the polygon. Another way of putting it is that a polygon is convex if and only if every internal angle is less than 180°.

A Convex polygon NOT a convex polygon
(Note how the line AC would be outside of the polygon, and the internal angle at B is greater than 180°)

Note: Points on the boundary of the polygon are regarded as being inside the polygon.

Test Data

(3,0),(2,3),(0,0)
(1,2)
(6,0),(6,4),(0,4),(0,0)
(2,3)
(0,1),(2,3),(5,1),(4,0),(1,0)
(1,2)
(1,1),(0,2),(1,10),(4,25),(8,40),(11,50),(20,30),(25,15),(10,0)
(10,47)

Sample Output

(1,2) is OUTSIDE the polygon
(2,3) is INSIDE the polygon
(1,2) is INSIDE the polygon

Constraints

You may assume all ordinates are integers and non-negative. You may assume the polygon has no more than 25 vertices. You may assume the vertices of the polygon are given in adjacent order.


Bonus Marks

Bonus marks will be awarded for a solution which does not assume that the vertices are in adjacent order.

Test Data

(5,1),(0,1),(4,0),(1,0),(2,3)
(1,2)
(0,0),(1,4),(3,0),(2,3)
(0,3)
(1,2),(1,4),(3,3),(0,3),(2,4),(2,2)
(2,3)
(6,11),(15,8),(0,2),(3,10),(8,0)
(14,9)

Sample Output

(1,2) is INSIDE the polygon


Task 6 - Paint Fill

Description

You are to write a program, which given several lines of text representing a picture, must fill the inside of an object.

Empty space will be indicated by '-' characters. The border of the object is indicated by '*'s. The filled image should be returned, also using '*'s. To aid you, one point inside the object to be filled will be given. It will be identified by an 'o'.

Test Data


---***--
-**---*-
-*-----*
-*-o--*-
--****--

-**---**-
*o-*-*--*
*---*---*
-*--*--*-
--*---*--
---*-*---
----*----
*******--
*------*-
-*****--*
------*o*
***---*-*
*-****--*
*------*-
-******--
--***--**-
-*---***-*
*------*-*
*-o--*---*
*---*-**-*
-*-*---***
--*-------

Sample Output

---***--
-******-
-*******
-******-
--****--
-**---**-
****-****
*********
-*******-
--*****--
---***---
----*----

Constraints

You may assume the lines of text will be rectangular. The line-length will be no more than 80 characters, and there will be no more than 24 lines.

You may assume there are no "pinched" shapes such as the figure 8 below:

--**--
-*--*-
-*-o-*
-*--*-
--**--
-*--*-
-*---*
-*--*-
--**--


- cut - here -

The University of New South Wales School of Computer Science and Engineering CSE/UNSW/CISRA High Schools Programming Competition 2002

Preliminary Round Submission Cover Sheet

This form must accompany the program listings and test runs produced by the team identified below, and must be signed by the supervisor. Please remember to submit one form for each team.

Name of School:
 
Name of Team:
 
Team Members: (Family names only)
 
 
 
Session Details:
Date:   Start Time:   Finish Time:  
 
Declaration: The apreached listings represent the work of the team named above, conducted under my supervision within the times indicated according to the competition rules. I have impressed upon all team members that they must not discuss details of the tasks with any person until Saturday 10 August 2002.
 
Supervisor Name:
 
Signed and Dated:
 

     

Summary of Tasks Attempted

Team member or supervisor to complete columns headed Code and (optionally) Remarks. Leave the Points column blank.

For each task, describe the team's achievement using one of these codes:
N/A   Task not attempted U/S   Attempted, but unsuccessfully
PART   A partially successful attempt (some apparently correct output)
OK   Task completed

Team member or supervisor to complete UNSW assessor use only
Task Attempt Remarks Points
1      
2      
3      
3 bonus      
4      
4 bonus      
5      
5 bonus      
6      
Total  

Return to: Programming Competition, School of Computer Science and Engineering, The University of New South Wales, Sydney NSW 2052

entries to be received by Friday 9 August 2002