Recently Added TSSOJ Problemshttps://tssoj.ca/The latest problems added on the Thornhill Secondary School Online Judge websiteen-caMon, 23 Nov 2020 02:03:29 +0000Hockey Scoreshttps://tssoj.ca/problem/hockeyscores<p>Hugh Hockey is a very big hockey fan. Every Saturday night he sits and watches all the hockey games, never wanting to miss a moment. Every Canadian loves hockey.</p>
<p>Not this Saturday night though. Hugh Hockey has a date, so he trained his three year-old brother Billy to record the scores for him. He sits Billy in front of his TV, teaches him how to change the channels, and tells him to write down the hockey scores.</p>
<p>Hugh returns home, after his date, to a surprise: he discovers that...Mon, 23 Nov 2020 02:03:29 +0000https://tssoj.ca/problem/hockeyscoresTSSPC '20 Contest 1 P5 - Trick or Trailhttps://tssoj.ca/problem/tsspc20c1p5<p>It's Halloween and [user:Henry_Zhang] loves candy, but is too scared to go trick or treating (he's very afraid). He lives in a terrifying grid neighbourhood of dimension \(n\) x \(m\). [user:sankeeth_ganeswaran] lives at \((0,0)\) and he wants to deliver candy to [user:Henry_Zhang] who lives at \((n,m)\). [user:sankeeth_ganeswaran] rides his old haunted broomstick but accidentally trips and squishes it, breaking it under all his weight! His broken broom can only fly him up or right on the gri...Tue, 20 Oct 2020 18:36:37 +0000https://tssoj.ca/problem/tsspc20c1p5UK Postal Codeshttps://tssoj.ca/problem/ukcodes<p>A postal code in the United Kingdom must come in one of the following formats:</p>
<pre><code>A9 9AA
A9A 9AA
A99 9AA
AA9 9AA
AA9A 9AA
AA99 9AA</code></pre>
<p>In the above formats, <code>A</code> is a placeholder for any lowercase <em>or</em> uppercase letter and <code>9</code> is a placeholder for any digit. For example <code>e5Y 8Qe</code> is a valid UK postal code because it follows the second format listed above. Given a string, determine if it is a valid UK postal code.</p>
<h4>Input Sp...Thu, 21 May 2020 22:46:38 +0000https://tssoj.ca/problem/ukcodesA Baker's Dozenhttps://tssoj.ca/problem/bakersdozen<p>When ordering a quantity of pastries, a baker's dozen is considered to be 13. At TSS Bakery, you are charged the cost of a dozen pastries when you purchase a baker's dozen, effectively giving you 1 for free. In addition to a separate cost for a dozen, there is another cost for individual pastries below a dozen. Given the costs as well as the number of pastries purchased, determine the final amount of the bill.</p>
<h4>Input Specification</h4>
<p>The first line of input is an integer \(b\) \((...Thu, 21 May 2020 22:16:04 +0000https://tssoj.ca/problem/bakersdozenLeap Yearhttps://tssoj.ca/problem/leapyear<p>A Leap Year is any year which satisfies one of the following conditions:</p>
<ul>
<li>The year is a multiple of 4, 100 and 400. </li>
<li>The year is a multiple of 4 but not a multiple of 100.</li>
</ul>
<p>Given a year, determine if it is a Leap Year. You may copy and paste the following Python function to check if a number is a multiple of another.</p>
<div class="codehilite"><pre><span></span><code><span class="k">def</span> <span class="nf">is_multiple</span><span class="p">(</span><span...Thu, 14 May 2020 11:47:03 +0000https://tssoj.ca/problem/leapyearOff Peakhttps://tssoj.ca/problem/offpeak<p>When calculating electricity bills, the hourly rate is based off of the time of day. During "on peak" hours, the hourly rate is higher then during "off peak" hours. Given a number, determine if it is a valid hour of the day (using 24 hour time) and if it is, determine if it is on peak or off peak. On peak hours are between and including 9 and 17 (5pm) o'clock. Off peak hours are any other time of day. Numbers greater then 24 are not valid times of day.</p>
<h4>Input Specification</h4>
<p>The ...Tue, 12 May 2020 23:56:09 +0000https://tssoj.ca/problem/offpeakInteger Typehttps://tssoj.ca/problem/integertype<p>Strings can represent even or odd numbers, but they also might not be numbers at all. Given a string, determine if it is an even integer, odd integer, or not an integer.</p>
<h4>Input Specification</h4>
<p>The only line of input is an alphanumeric sequence of characters containing only digits and lowercase letters.</p>
<h4>Output Specification</h4>
<p>If the input was an even integer, print <code>even</code>, if it was an odd integer, print <code>odd</code>. If it was not a valid integer, pri...Tue, 12 May 2020 23:47:08 +0000https://tssoj.ca/problem/integertypeMax of Threehttps://tssoj.ca/problem/maxofthree<p>Given three numbers, your task is to determine which of them is the biggest.</p>
<h4>Input Specification</h4>
<p>There will be three lines of input each containing an integer between <code>1</code> and <code>1 million</code>.</p>
<h4>Output Specification</h4>
<p>Print the greatest integer of the three.</p>
<h4>Sample Input</h4>
<pre><code>8392
52
53494</code></pre>
<h4>Sample Output</h4>
<pre><code>53494</code></pre>
...Tue, 12 May 2020 22:05:45 +0000https://tssoj.ca/problem/maxofthreeRoman Numerals Ihttps://tssoj.ca/problem/romannumeralsi<p>The numbering system we use today is known as <em>Arabic Numerals</em>. The ancient Romans used a numbering system called <em>Roman Numerals</em>. The following is a conversion table for converting Arabic Numerals to Roman Numerals.</p>
<pre><code>1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VIII
9 IX
10 X</code></pre>
<p>Given an Arabic Numeral from <code>1-10</code>, determine the corresponding Roman Numeral.</p>
<h4>Input Specification</h4>
<p>The only line of input i...Tue, 12 May 2020 21:22:02 +0000https://tssoj.ca/problem/romannumeralsiCharacter Switchhttps://tssoj.ca/problem/charswitch<p>Write a program that takes a string of length at least two as input and then prints a string formed by exchanging the first and last characters in the string provided.</p>
<h4>Input</h4>
<p>A String of length 2 or more.</p>
<h4>Output</h4>
<p>A new String that has the first and last characters switched.</p>
<h4>Sample Input</h4>
<pre><code>red</code></pre>
<h4>Sample Output</h4>
<pre><code>der</code></pre>
...Thu, 16 Apr 2020 14:13:50 +0000https://tssoj.ca/problem/charswitchHeart Ratehttps://tssoj.ca/problem/heartrate<p>The target heart rate can be obtained by adding the resting heart rate to the product of the target intensity (a number between 0 and 1) and the heart rate reserve.</p>
<p>The heart rate reserve is the difference between the maximum heart rate and the resting heart rate.</p>
<p>The maximum heart rate is calculated as 220 minus the age.</p>
<p>For the values given, print the target heart rate.</p>
<h4>Input</h4>
<p>The inputs are age, resting heart rate and intensity.</p>
<h4>Output</h4>
<p>Th...Wed, 15 Apr 2020 23:36:05 +0000https://tssoj.ca/problem/heartrateBackwards Treehttps://tssoj.ca/problem/backwardstree<p>Leonhard Euler famously solved The Seven Bridges of Königsberg problem, leading to the establishment of graph theory. Overjoyed by the creation of a new branch of mathematics, Euler decided to pose himself a problem.</p>
<p>First, Euler gives himself \(N\) nodes and \(N-1\) edges to build a <strong>directed graph (a directed tree with all edges pointing away from root node)</strong>, labelling each node from \(1\) to \(N\). The \(i^{th}\) node is assigned a value, \(V\), of \(\frac{1}{2^i}\)....Thu, 12 Mar 2020 21:59:07 +0000https://tssoj.ca/problem/backwardstreeJonathan Sumabat 9.5https://tssoj.ca/problem/0jsumabat9point5<p>Jonathan Sumabat is a world class Osu! player. He is known for developing new techniques to play that have been widely adapted across the game. One of these techniques is called <em>hacking into Osu! servers and changing the score</em>. This is where Jonathan Sumabat hacks into Osu! servers and changes his score. However, due to his limited access, the only option he has is to switch the first and last digits of his score. After changing a number of different scores, Jonathan Sumabat forgets ...Thu, 12 Mar 2020 00:48:57 +0000https://tssoj.ca/problem/0jsumabat9point5Theory of Relativityhttps://tssoj.ca/problem/theoryofrelativity<p>Albert Einstein was a renowned theoretical physicist who developed the famous equation \(E=mc^2\). Albert Einstein is now working on a thesis he calls the Theory of Special Relativity which posits a set of universal truths about the behavior of light and motion of objects. When developing his thesis, Einstein selects evidence to support his hypothesis based on a "reliability ratio". He selects a set of trials from various different experiments such that the sum of the reliability ratio is max...Tue, 10 Mar 2020 17:32:43 +0000https://tssoj.ca/problem/theoryofrelativityLady of the Lakehttps://tssoj.ca/problem/ladyofthelake<p>King Arthur Pendragon is said to have been a great king of Britain, wielding the legendary sword Excalibur. After his final battle and the defeat of his nemesis, Mordred, King Arthur must return his sword to the one who gave it to him, the Lady of the Lake. The Lady of the Lake speaks an ancient language that only King Arthur understands. To the human ear, the language of the Lady of the Lake takes every letter in her speech, and shifts forward every letter by the absolute value of the differ...Mon, 09 Mar 2020 17:15:57 +0000https://tssoj.ca/problem/ladyofthelakeEncryption by Reversalhttps://tssoj.ca/problem/encryptionbyreversal<p>John von Neumann was a Hungarian-American scholar who worked on developing the world's first nuclear weapons during World War II. He is highly regarded as one of the greatest mathematicians of his time. One day, John von Neumann is testing a new algorithm he created called "Mergesort" using a set of numbers he generated. Because he wants to keep his work on Mergesort secret, John von Neumann devises a way to encrypt his numbers. Starting from the original sorted set of numbers, he selects som...Sat, 07 Mar 2020 01:35:22 +0000https://tssoj.ca/problem/encryptionbyreversalCinematographyhttps://tssoj.ca/problem/cinematography<p>Charlie Chaplin is seen as one of the most influential cinematographers of all time, rising to fame during the era of silent film. During this era, film was projected onto the big screen from a roll of tape. The film is connected from beginning to end, meaning after the film finishes rolling, it is looped back to the start and played again. At a screening of one of his films, Charlie Chaplin notices that the film roll is misaligned in the projector, causing the movie to start from somewhere i...Thu, 05 Mar 2020 23:41:13 +0000https://tssoj.ca/problem/cinematographyBalanced Reactionshttps://tssoj.ca/problem/balancedreactions<p>In Chemistry all elements are represented as one or two characters. The element always begins with a capital letter and if there is a second letter it is always a lowercase. Sometimes multiple elements can be combined to create a single compound. When multiple of a given element is included in this compound a number representing the quantity of that element is appended to the end of the element's letter code. It is also possible for an element to appear more than once in a compound, for examp...Wed, 04 Mar 2020 18:23:18 +0000https://tssoj.ca/problem/balancedreactionsTSS Contest P1 - Over and Underhttps://tssoj.ca/problem/tsscc20j1<p>Prom is coming up and you want to ask your high school crush to be your date to the event. To do this, you decide to sew them a red and green scarf as a present. Sewing, as it turns out, is not as easy as it may seem. You have an array of red and green threads lined up and you want to run a black thread perpendicular to it, going over each red thread and under each green thread like this:</p>
<p><img src="https://i.imgur.com/Gez8nk9.png" alt="threads"></p>
<p>Though seemingly a simple task yo...Fri, 14 Feb 2020 04:04:08 +0000https://tssoj.ca/problem/tsscc20j1TSS Contest P7 - Point Queryhttps://tssoj.ca/problem/tsscc20j11<p>Given \(N\) points and \(Q\) queries, both of the form \(x\), \(y\), determine the Manhattan distance of the point closest to each query.</p>
<p><strong>Manhattan distance</strong> is defined as the distance between two points measured along horizontal and vertical lines only.</p>
<p>All points and queries will be in the first quadrant (\( 0 \le x,y \le 10^3\)).</p>
<h4>Input Specifications</h4>
<p>The first line contains the integers, \(N\) and \(Q\) where \(1 \le N \le 10^6.\) and \(1 \le Q...Thu, 13 Feb 2020 22:41:00 +0000https://tssoj.ca/problem/tsscc20j11TSS Contest P6 - Tic Tac Toehttps://tssoj.ca/problem/tsscc20j6<p>Tic Tac Toe is a game played on a 3x3 grid. The two players take turns placing an <code>x</code> or an <code>o</code> on an unoccupied cell. A player wins when they have three matching symbols in a vertical, horizontal or diagonal line. If no one wins after all 9 cells have been taken the game results in a draw. If a player can create a situation where there are two possible moves to win the game, they are guaranteed an opportunity to win if the game does not end before their next turn. This ...Thu, 13 Feb 2020 22:40:46 +0000https://tssoj.ca/problem/tsscc20j6TSS Contest P5 - Blob Lifehttps://tssoj.ca/problem/tsscc20j5<p>A blob of mass \(N\) has discovered it has the ability to separate itself into \(P\) parts an infinite number of times. However, the blob does not split into \(P\) <strong>equal</strong> parts, but rather every \(i^{th}\) part will contain \(p_i\)% of the blob's mass. Each split creates more blobs which also split, meaning the number of blobs multiplies every split. If the original blob of mass \(N\) splits into \(P\) parts \(M\) times, what is the mass of the \(k^{th}\) smallest blob?</p>
<p...Thu, 13 Feb 2020 22:40:13 +0000https://tssoj.ca/problem/tsscc20j5TSS Contest P3 - Pizza Sandwichhttps://tssoj.ca/problem/tsscc20j3<p>A square pizza slice is broken down into a \(N\) by \(N\) grid. Each cell in this grid is assigned a deliciousness value, \(V\). A basic pizza slice would look like the below:</p>
<pre><code>1 2 1
1 3 1
1 1 3</code></pre>
<p>A chef has discovered that folding this square pizza slice in half across a diagonal results in optimal deliciousness per bite, known as a pizza sandwich. The diagonal is represented on the pizza slice as a series of <code>0</code>s, replacing some deliciousness values f...Thu, 13 Feb 2020 22:39:44 +0000https://tssoj.ca/problem/tsscc20j3TSS Contest P2 - Magnetshttps://tssoj.ca/problem/tsscc20j2<p>A line of magnets can be represented as a string of <code>-</code>s, <code>+</code>s and <code>0</code>s representing negative, positive and neutral charges respectively. A single magnet will always be composed of either a <code>-</code> or <code>+</code> at either end (these magnets can have both ends with the same charge) and at least one <code>0</code> in the middle. For example, <code>-00+</code>, <code>-00000000-</code> and <code>+0-</code> are all valid magnets. Consider the following s...Thu, 13 Feb 2020 22:39:30 +0000https://tssoj.ca/problem/tsscc20j2TSS Contest P4 - Debate Tournamenthttps://tssoj.ca/problem/tsscc20j4<p>Thornhill Secondary School is hosting its 17th annual debate tournament! You, as a debate tournament volunteer are helping organize the event. Your task is to decide the pairings for the next round of debates based on each team's win rate. A team's win rate is defined as simply the number of rounds that team already won. When pairing teams, you must match the team with the highest win rate against the team with the lowest win rate, then the team with the second highest win rate against the te...Thu, 13 Feb 2020 16:48:09 +0000https://tssoj.ca/problem/tsscc20j4