The British Informatics Olympiad (BIO) is an annual competition in computer programming for secondary schools. The first stage of the BIO is a three-hour exam, taken at school, in which students solve problems with the aid of a computer. These are marked by a teacher and submitted for moderation. Based on the results of this exam, the top 15 competitors are invited to the BIO final in Cambridge during the Easter holidays. The best four make up the team to represent Britain at the IOI.
Rules
Students must write 3 different programs. Each program will have 2 small follow up questions.
Student will have 3 hours of supervised time to completed the competition
All programs should run for no more than 1 second
No AI or non standard libraries, students can only use the internet to look up documentation of their language
Student may use a high level language of their choice (If invited to cambridge you will need to write in C or C++).
Website
Orginal question
Every positive integer can be represented by a palindromic sum of at most three palindromic numbers (numbers that remain the same when their digits are reversed).
To be a valid palindromic sum for an integer, the sum must contain the smallest possible number of palindromic numbers. It can contain duplicates. For example:
12321 is a palindromic number already, so can be formed from just 12321;
9610 is equal to 161 + 9449, which is the only pair of palindromic numbers that sum to 9610. There are triplets that sum to 9610, such as 282 + 1771 + 7557, but those contain too many palindromic numbers;
1031 requires three palindromic numbers such as 2 + 494 + 535 and 4 + 88 + 939.
Write a program that reads in an integer (between 1 and 1,000,000 inclusive) and outputs 1, 2 or 3 palindromic numbers which together form a minimal length palindromic sum for the input. If there are several possible palindromic sums you should output the one containing the lowest palindromic number. If there are still several solutions remaining you should select the one containing the highest palindromic number.
Student friendly
Every positive whole number can be made by adding together one, two or three palindromic numbers.
A palindromic number is a number that reads the same forwards and backwards.
For example:
121 is a palindrome.
4554 is a palindrome.
1234 is not a palindrome.
Your challenge is to find the smallest number of palindromic numbers needed to make a given total.
You can use the same palindromic number more than once.
Example 1: Making 12321
12321 is already a palindrome, so you only need one number.
12321 = 12321
Example 2: Making 9610
You can make 9610 using two palindromic numbers:
9610 = 161 + 9449
This is the smallest possible number of palindromes needed. There are ways to make 9610 using three palindromes, but we want to use as few numbers as possible.
Example 3: Making 1031
1031 cannot be made using just one or two palindromic numbers, so you need three.
For example:
1031 = 2 + 494 + 535
Or
1031 = 4 + 88 + 939
Both are valid answers.
Write a program that reads in an integer (between 1 and 1,000,000 inclusive)
Output the palindromic numbers required to be added together to make that number
Always pick the smallest amount of palindromic numbers (e.g only 2 numbers required instead of 3).
Sample run
Input - 1031
Output - 1 101 929
Orginal Question
A fuse is a length of material that can be burned. This is an irregular process but when lit from one end a fuse completes burning in a fixed amount of time. If lit from both ends it will take half this time. A fuse can only be used once and when it has started to burn it cannot be paused.
Given several fuses we can measure different continuous periods of time by lighting fuses when other fuses have finished burning. Fuses are lit at the instant another fuse stops burning and multiple fuses can be lit simultaneously. We cannot measure time in any other way.
For example, given two fuses with a burn time of 1, we can measure various times as follows:
• 0 — do not light any fuse;
• 1 — light a single fuse at one end;
• 2 — light a fuse at one end. When it finishes burning (at 1) light the other fuse at one end;
• 0.5 — light both ends of a fuse simultaneously;
• 1.5 — light both ends of a fuse simultaneously. When it finishes burning, light the other fuse at one end;
• 0.75 — light both ends of the first fuse and one end of the second fuse simultaneously. At 0.5 the first fuse has finished and the second has another 0.5 to burn. At this point light the second end of the second fuse, so it completes burning in 0.25;
• 0.25 — follow the directions for 0.75 but only start timing the period after the first fuse has finished.
Write a program to determine the number of distinct periods that can be measured by a set of fuses. Your program should first input a single integer, f (1 ≤ f ≤ 4), indicating the number of fuses. You should then input f integers, each between 1 and 5000 inclusive, giving the burn times for each fuse. You should output the number of possible periods that we can time with these fuses.
Imagine you have several fuses. Each fuse takes a fixed amount of time to burn completely
There are a few important rules:
You can light a fuse at one end or both ends.
If you light both ends at the same time, the fuse will burn out in half its normal time.
Once a fuse has been lit, you cannot stop it or pause it.
Each fuse can only be used once.
You can light another fuse when an existing fuse finishes burning.
You can light several fuses at the same time.
You can only measure time using the fuses. You cannot use a clock or stopwatch.
Imagine you have two fuses, and each takes 1 minute to burn completely.
Using these two fuses, you can measure several different lengths of time.
Write a program that works out how many different lengths of time can be measured using a given collection of fuses.
Your program should:
Ask the user to enter the number of fuses they have (between 1 and 4).
Ask the user to enter the burning time for each fuse (between 1 and 5000).
Calculate how many different time periods can be measured using those fuses.
Output the total number of distinct time periods.
Important: If two different methods measure exactly the same amount of time, this only counts as one distinct time period.
Sample run
INPUT 1 (number of fuses) - 2
INPUT 2 (Burn time for each fuse) - 1 1
OUTPUT - 7
Word Game In a word game letters are scored according to their position in the alphabet (A=1, …, Z=26) and a word’s score is the sum of scores of its letters. Any combination of letters is allowed in a word, so long as there are no adjacent copies of the same letter.
Given a word, we are interested in finding its position in the alphabetically ordered list of words with the same score.
For example, there are 7 words which score 5. The word BAB is the 3rd word in the list, which is:
ACA
AD
BAB
BC
CB
DA
E
Write a program to determine the position of a word in its list. Your program should first input a string of 1 to 12 uppercase letters. The score of this string will be ≤ 75. You should output the position of this string in the alphabetically ordered list of words with the same score.
Student friendly wording
In this word game, each letter is given a score based on its position in the alphabet:
A = 1
B = 2
C = 3
...
Z = 26
A word's total score is calculated by adding together the scores of all its letters.
There is one rule: the same letter cannot appear twice in a row. Any other combination of letters is allowed.
We want to find out where a given word would appear in an alphabetical list of all words with the same total score
Write a program that finds the position of a given word in its alphabetical list.
Your program should:
Ask the user to enter a word containing between 1 and 12 uppercase letters.
Calculate the word's total score.
Find all possible words with the same score, following the rule that identical letters cannot appear next to each other.
Arrange these words in alphabetical order.
Output the position of the original word in the list.
Sample run
INPUT - BAB
OUTPUT - 3