2020 Canadian Computing Competition
Junior Problems
Problem J1: Dog Treats
Problem Description
Barley the dog loves treats. At the end of the day he is either happy or
sad depending on the number and size of treats he receives throughout
the day. The treats come in three sizes: small, medium, and large. His
happiness score can be measured using the following formula:
where is the number of small
treats, is the number of medium
treats and is the number of large
treats.
If Barley’s happiness score is or greater then he is happy.
Otherwise, he is sad. Determine whether Barley is happy or sad at the
end of the day.
Input Specification
There are three lines of input. Each line contains a non-negative
integer less than . The first
line contains the number of small treats, , the second line contains the number of
medium treats, , and the third
line contains the number of large treats, , that Barley receives in a day.
Output Specification
If Barley’s happiness score is
or greater, output happy
. Otherwise, output
sad
.
Sample Input 1
3
1
0
Output for Sample Input 1
sad
Explanation of Output for Sample Input 1
Barley’s happiness score is , so he will be sad.
Sample Input 2
3
2
1
Output for Sample Input 2
happy
Explanation of Output for Sample Input 2
Barley’s happiness score is , so he will be happy.
Problem J2: Epidemiology
Problem Description
People who study epidemiology use models to analyze the spread of
disease. In this problem, we use a simple model.
When a person has a disease, they infect exactly other people but only on the very next
day. No person is infected more than once. We want to determine when a
total of more than people have
had the disease.
(This problem was designed before the current coronavirus
outbreak, and we acknowledge the distress currently being experienced by
many people worldwide because of this and other diseases. We hope that
including this problem at this time highlights the important roles that
computer science and mathematics play in solving real-world
problems.)
Input Specification
There are three lines of input. Each line contains one positive integer.
The first line contains the value of . The second line contains , the number of people who have the
disease on Day . The third line
contains the value of . Assume
that and and .
Output Specification
Output the number of the first day on which the total number of people
who have had the disease is greater than .
Sample Input 1
750
1
5
Output for Sample Input 1
4
Explanation of Output for Sample Input 1
The person on Day with the disease infects people on Day . On Day , exactly people are infected. On Day , exactly people are infected. A total of people have had the
disease by the end of Day and
.
Sample Input 2
10
2
1
Output for Sample Input 2
5
Explanation of Output for Sample Input 2
There are people on Day 0 with
the disease. On each other day, exactly people are infected. By the end of Day
, a total of exactly people have had the disease and by the
end of Day , more than people have had the disease.
Problem J3: Art
Problem Description
Mahima has been experimenting with a new style of art. She stands in
front of a canvas and, using her brush, flicks drops of paint onto the
canvas. When she thinks she has created a masterpiece, she uses her 3D
printer to print a frame to surround the canvas.
Your job is to help Mahima by determining the coordinates of the
smallest possible rectangular frame such that each drop of paint lies
inside the frame. Points on the frame are not considered inside the
frame.
Input Specification
The first line of input contains the number of drops of paint, , where and is an
integer. Each of the next lines
contain exactly two positive integers and separated by one comma (no spaces).
Each of these pairs of integers represents the coordinates of a drop of
paint on the canvas. Assume that and , and
that there will be at least two distinct points. The coordinates represent the bottom-left corner of
the canvas.
For 12 of the 15 available marks, and will both be two-digit integers.
Output Specification
Output two lines. Each line must contain exactly two non-negative
integers separated by a single comma (no spaces). The first line
represents the coordinates of the bottom-left corner of the rectangular
frame. The second line represents the coordinates of the top-right
corner of the rectangular frame.
Sample Input
5
44,62
34,69
24,78
42,44
64,10
Output for Sample Input
23,9
65,79
Explanation of Output for Sample Input
The bottom-left corner of the frame is . Notice that if the bottom-left
corner is moved up, the paint drop at will not be inside the frame.
(See the diagram below.) If the corner is moved right, the
paint drop at will not be
inside the frame. If the corner is moved down or left, then the frame
will be larger and no longer the smallest rectangle containing all the
drops of paint. A similar argument can be made regarding the top-right
corner of the frame.
Problem J4: Cyclic Shifts
Problem Description
Thuc likes finding cyclic shifts of strings. A cyclic
shift of a string is obtained by moving characters from the
beginning of the string to the end of the string. We also consider a
string to be a cyclic shift of itself. For example, the cyclic shifts of
ABCDE
are:
ABCDE
, BCDEA
,
CDEAB
, DEABC
, and
EABCD
.
Given some text, , and a
string, , determine if contains a cyclic shift of .
Input Specification
The input will consist of exactly two lines containing only uppercase
letters. The first line will be the text , and the second line will be the string
. Each line will contain at most
characters.
For 6 of the 15 available marks, will be exactly characters in length.
Output Specification
Output yes
if the text, , contains a cyclic shift of the string,
. Otherwise, output
no
.
Sample Input 1
ABCCDEABAA
ABCDE
Output for Sample Input 1
yes
Explanation of Output for Sample Input 1
CDEAB
is a cyclic shift of
ABCDE
and it is contained in the text
ABCCDEABAA
.
Sample Input 2
ABCDDEBCAB
ABA
Output for Sample Input 2
no
Explanation of Output for Sample Input 2
The cyclic shifts of ABA
are
ABA
, BAA
, and
AAB
. None of these shifts are contained in the
text ABCDDEBCAB
.
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
.