Halloween Sale

You wish to buy video games from the famous online video game store Mist.

Usually, all games are sold at the same price, p dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game you buy during the sale will be sold at p dollars, but every subsequent game you buy will be sold at exactly d dollars less than the cost of the previous one you bought. This will continue until the cost becomes less than or equal to m dollars, after which every game you buy will cost m dollars each.

For example, if p = 20, d = 3 and m = 6, then the following are the costs of the first 11 games you buy, in order:

20, 17, 14, 11, 8, 6, 6, 6, 6, 6, 6

You have s dollars in your Mist wallet. How many games can you buy during the Halloween Sale?


Minimum Distances

We define the distance between two array values as the number of indices between the two values. Given a, find the minimum distance between any pair of equal elements in the array. If no such value exists, print -1.

For example, if a = [3, 2, 1, 2, 3], there are two matching pairs of values: 3 and 2. The indices of the 3‘s are i = 0 and j = 4, so their distance is d[i, j] = |j - i| = 4. The indices of the 2‘s are i = 1 and j = 3, so their distance is d[i, j] = |j - i| = 2.


Beautiful Triplets

Given a sequence of integers a, a triplet (a[i], a[j], a[k]) is beautiful if:

  • i < j < k
  • a[j] - a[i] = a[k] - a[j] = d

Given an increasing sequenc of integers and the value of d, count the number of beautiful triplets in the sequence.

For example, the sequence arr = [2, 2, 3, 4, 5] and d = 1. There are three beautiful triplets, by index: [i, j, k] = [0, 2, 3], [1, 2, 3], [2, 3, 4]. To test the first triplet, arr[j] - arr[i] = 3 - 2 = 1 and arr[k] = arr[j] = 4 - 3 = 1.


Modified Kaprekar Numbers

A modified Kaprekar number is a positive whole number with a special property. If you square it, then split the number into two integers and sum those integers, you have the same value you started with.

Consider a positive whole number n with d digits. We square n to arrive at a number that is either 2 x d digits long or (2 x d) - 1 digits long. Split the string representation of the square into two parts, l and r. The right hand part, r must be d digits long. The left is the remaining substring. Convert those two substrings back to integers, add them and see if you get n.

For example, if n = 5, d = 1 then . We split that into two strings and convert them back to integers 2 and 5. We test , so this is not a modified Kaprekar number. If n = 9, still d = 1, and . This gives us 1 + 8 = 9, the original n.

Note: r may have leading zeros.

Encryption

An English text needs to be encrypted using the following encryption scheme.
First, the spaces are removed from the text. Let L be the length of this text.
Then, characters are written into a grid, whose rows and columns have the following constraints:

For example, the sentence
s = if man was meant to stay on the ground god would have given us roots, after removing spaces is 54 characters long. is between 7 and 8, so it is written in the form of a grid with 7 rows and 8 columns.


Taum and B'day

Taum is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buy b black gifts and w white gifts.

  • The cost of each black gift is bc units.
  • The cost of every white gift is wc units.
  • The cost of converting each black gift into white gift or vice versa is z units.

Help Taum by deducing the minimum amount he needs to spend on Diksha’s gifts.

For example, if Taum wants to buy b = 3 black gifts and w = 5 white gifts at a cost of bc = 3, wc = 4 and conversion cost z = 1, we see that he can buy a black gift for 3 and convert it to a white gift for 1, making the total cost of each white gift 4. That matches the cost of a white gift, so he can do that or just buy black gifts and white gifts. Either way, the overall cost is 3 * 3 + 5 * 4 = 29.


Cut the sticks

You are given a number of sticks of varying lengths. You will iteratively cut the sticks into smaller sticks, discarding the shortest pieces until there are none left. At each iteration you will determine the length of the shortest stick remaining, cut that length from each of the longer sticks and then discard all the pieces of that shortest length. When all the remaining sticks are the same length, they cannot be shortened so discard them.

Given the lengths of n sticks, print the number of sticks that are left before each iteration until there are none left.

For example, there are n = 3 sticks of lengths arr = [1, 2, 3]. The shortest stick length is 1, so we cut that length from the longer two and discard the pieces of length 1. Now our lengths are arr = [1, 2]. Again, the shortest stick is of length 1, so we cut that amount from the longer stick and discard those pieces. There is only one stick left, arr = [1], so we discard that stick. Our lengths are answer = [3, 2, 1].


Jumping on the Clouds

Emma is playing a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. She can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus 1 or 2. She must avoid the thunderheads. Determine the minimum number of jumps it will take Emma to jump from her starting postion to the last cloud. It is always possible to win the game.

For each game, Emma will get an array of clouds numbered 0 if they are safe or 1 if they must be avoided. For example, c = [0, 1, 0, 0, 0, 1, 0] indexed from 0 … 6. The number on each cloud is its index in the list so she must avoid the clouds at indexes 1 and 5. She could follow the following two paths: 0 -> 2 -> 4 -> 6 or 0 -> 2 -> 3 -> 4 -> 6. The first path takes 3 jumps while the second takes 4.


ACM ICPC Team

There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, you must determine the maximum number of topics a 2-person team can know. Also find out how many ways a team can be formed to know that many topics. Lists will be in the form of bit strings, where each string represents an attendee and each position in that string represents a field of knowledge, 1 if its a known field or 0 if not.

For example, given three attendees’ data as follows:

1
2
3
10101
11110
00010

These are all possible teams that can be formed:

Members Subjects

1
2
3
(1,2)   [1,2,3,4,5]
(1,3) [1,3,4,5]
(2,3) [1,2,3,4]

In this case, the first team will know all 5 subjects. They are the only team that can be created knowing that many subjects.


Equalize the Array

Karl has an array of integers. He wants to reduce the array until all remaining elements are equal. Determine the minimum number of elements to delete to reach his goal.

For example, if his array is arr = [1, 2, 2, 3], we see that he can delete the 2 elements 1 and 3 leaving arr = [2, 2]. He could also delete both twos and either the 1 or the 3, but that would take 3 deletions. The minimum number of deletions is 2.


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×