2020 Canadian Computing Competition
Senior Problems
Problem S1: Surmising a Sprinter’s
Speed
Problem Description
Trick E. Dingo is trying, as usual, to catch his nemesis the Street
Sprinter. His past attempts using magnets, traps and explosives have
failed miserably, so he’s catching his breath to gather observational
data and learn more about how fast Street Sprinter is.
Trick E. Dingo and Street Sprinter both inhabit a single straight
west-east road with a particularly famous rock on it known
affectionately as The Origin. Positions on this straight road are
measured numerically according to the distance from The Origin, and
using negative numbers for positions west of The Origin and positive
numbers for positions east of The Origin.
The observations by Trick E. Dingo each contain two numbers: a time,
and the value of Street Sprinter’s position on the road at that time.
Given this information, what speed must Street Sprinter must be capable
of?
Input Specification
The first line contains a number , the number of observations that follow. The next
lines each contain an integer
indicating the time, in seconds, of when a measurement was made, and an
integer indicating the position, in metres, of the Street
Sprinter at that time. No two lines will have the same value of .
For 7 of the 15 available marks, .
Output Specification
Output a single number , such that
we can conclude that Street Sprinter’s speed was at least metres/second at some point in time,
and such that is as large as
possible. If the correct answer is , the grader will view as correct if .
Sample Input 1
3
0 100
20 50
10 120
Output for Sample Input 1
7.0
Explanation of Output for Sample Input 1
Since the Street Sprinter ran from position 100 to position 120 between
time 0 and time 10, we know its speed must have been at least at some point in time: if it was always
less than , then the distance of
20 could not be covered in 10 seconds. Likewise, the speed must have
been at least 7 in order to travel between position 120 and 50 in 10
seconds.
Sample Input 2
5
20 -5
0 -17
10 31
5 -3
30 11
Output for Sample Input 2
6.8
Problem J5/S2: Escape Room
Problem Description
You have to determine if it is possible to escape from a room. The room is an -by- grid with each position (cell) containing a positive integer. The rows are numbered and the columns are numbered
. We use to refer to the cell in row and column .
You start in the top-left corner at and exit from the bottom-right
corner at . If you are in a cell containing the value , then you can jump to any cell satisfying . For example, if you are in a cell containing a , you can jump to cell .
Note that from a cell containing a , there are up to four cells
you can jump to: , , , or . If the room is a -by- grid, there isn’t a row so only the first three jumps would be
possible.
Input Specification
The first line of the input will be an integer . The second line of the input will be an integer . The remaining input gives the positive integers in the cells of the room with rows and columns. It consists of lines where each line contains positive integers, each less than or equal to , separated by single
spaces.
For 1 of the 15 available marks, and .
For an additional 2 of the 15 available marks, .
For an additional 4 of the 15 available marks, all of the integers in
the cells will be unique.
For an additional 4 of the 15 available marks, and .
Output Specification
Output yes
if it is possible to escape from
the room. Otherwise, output no
.
Sample Input
3
4
3 10 8 14
1 11 12 12
6 2 3 9
Output for Sample Input
yes
Explanation of Output for Sample Input
Starting in the cell at which
contains a , one possibility is to
jump to the cell at . This
cell contains an so from it, you
could jump to the cell at .
This brings you to a cell containing from which you can jump to the exit at
. Note that another way to
escape is to jump from the starting cell to the cell at to the cell at to the exit.
Notes
The online grader begins by testing submissions using the sample input. All other tests are skipped if the sample test is not passed. If you are only attempting the first three subtasks (the first 7 marks), then you might want to handle the specific values of the sample input as a special case.
For the final subtask (worth 2 marks), if you are using Java, then Scanner
will probably take too long to read in the large amount of data. A much faster alternative is BufferedReader
.
Problem S3: Searching for Strings
Problem Description
You’re given a string , called the
needle, and a string , called the
haystack, both of which contain only lowercase
letters “a"..“z".
Write a program to count the number of distinct permutations of which appear as a substring of at least once. Note that can have anywhere between 1 and distinct permutations in total – for
example, the string “aab" has 3 distinct permutations (“aab", “aba", and
“baa").
Input Specification
The first line contains , the needle
string.
The second line contains
, the
haystack string.
For 3 of the 15 available marks, and .
For an additional 2 of the 15 available marks, and .
For an additional 2 of the 15 available marks, and .
Output Specification
Output consists of one integer, the number of distinct permutations of
which appear as a substring of
.
Sample Input
aab
abacabaa
Output for Sample Input
2
Explanation of Output for Sample Input
The permutations “aba" and “baa" each appear as substrings of (the former appears twice), while the
permutation “aab" does not appear.
Problem S4: Swapping Seats
Problem Description
There are people sitting at a
circular table for a long session of negotiations. Each person belongs
to one of the three groups: A
,
B
, or C
. A group is
happy if all of its members are sitting contiguously in a block
of consecutive seats. You would like to make all groups happy by some
sequence of swap operations. In each swap operation, two people
exchange seats with each other. What is the minimum number of swaps
required to make all groups happy?
Input Specification
The input consists of a single line containing characters, where each character is
A
, B
, or
C
. The -th character denotes the group of the
person initially sitting at the -th seat at the table, where seats are
numbered in clockwise order.
For 4 of the 15 available marks, the input has no
C
characters and .
For an additional 4 of the 15 available marks, the input has no
C
characters.
For an additional 4 of the 15 available marks, .
Output Specification
Output a single integer, the minimum possible number of swaps.
Sample Input
BABCBCACCA
Output for Sample Input
2
Explanation of Output for Sample Input
In one possible sequence, the first swap results in the seating layout
AABCBCBCCA
. After the second swap, the layout
is AABBBCCCCA
.
Problem S5: Josh’s Double Bacon Deluxe
Problem Description
On their way to the contest grounds, Josh, his coach, and his teammates decide to stop at a burger
joint that offers distinct burger
menu items. After ordering their favourite burgers, the team members
line up, with the coach in the first position and Josh last, to pick up
their burgers. Unfortunately, the coach forgot what he ordered. He picks
a burger at random and walks away. The other team members, in sequence,
pick up their favourite burger if available, or a random remaining
burger if there are no more of their favourite burger. What is the
probability that Josh, being last in line, will get to eat his favourite
burger?
Input Specification
The first line contains the number , the total number of people and burgers. The
next line contains numbers, the
-th being , denoting the item number of the -th person’s favourite burger. The first
person in line is the coach, and the -th person is Josh.
For 4 of the 15 available marks, and .
For an additional 5 of the 15 available marks, .
Output Specification
Output a single number , the
probability that Josh will get to eat his favourite burger, . If the correct answer is , the grader will view correct if .
Sample Input 1
3
1 2 3
Output for Sample Input 1
0.5
Explanation of Output for Sample Input
The coach randomly chooses between the three burgers. With probability
, he chooses his favourite
burger (burger 1), and Josh gets to eat his favourite burger (burger 3).
With probability , he chooses
Josh’s favourite burger, and Josh fails to eat his favourite burger.
With probability , he chooses
the second person’s burger, there is a chance that the second person chooses
Josh’s burger, denying Josh the pleasure of eating his favourite
burger.
Sample Input 2
7
1 2 3 1 1 2 3
Output for Sample Input 2
0.57142857