An anagram of a string is formed by rearranging the letters in the string. For example, the anagrams of aab are aab, aba, and baa.
A wildcard anagram of a string is an anagram of the string where some of the letters might have been replaced with an asterisk (*). For example, two possible wildcard anagrams of aab are ab and b*.
Given two strings, determine whether the second string is a wildcard anagram of the first string.
The two lines of input will both consist of
For 8 of the 15 available marks, the second line will not contain any asterisk characters.
Output the character A
if the string on the
second line is a wildcard anagram of the string on the first line.
Otherwise, output the character N
.
abba
baaa
N
cccrocks
socc*rk*
A
Since time immemorial, the citizens of Dmojistan and Pegland have
been at war. Now, they have finally signed a truce. They have decided to
participate in a tandem bicycle ride to celebrate the truce. There are
Each citizen has a cycling speed. In a pair, the fastest person will
always operate the tandem bicycle while the slower person simply enjoys
the ride. In other words, if the members of a pair have speeds
For this problem, in each test case, you will be asked to answer one of two questions:
Question 1: what is the minimum total speed, out of all possible assignments into pairs?
Question 2: what is the maximum total speed, out of all possible assignments into pairs?
The first line will contain the type of question you are to solve,
which is either
The second line contains
The third line contains
The fourth line contains
Each person’s speed will be an integer between
For 8 of the 15 available marks, questions of type
Output the maximum or minimum total speed that answers the question asked.
1
3
5 1 4
6 2 4
12
There is a unique optimal solution:
Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 6.
Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 2.
Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.
2
3
5 1 4
6 2 4
15
There are multiple possible optimal solutions. Here is one optimal solution:
Pair the citizen from Dmojistan with speed 5 and the citizen from Pegland with speed 2.
Pair the citizen from Dmojistan with speed 1 and the citizen from Pegland with speed 6.
Pair the citizen from Dmojistan with speed 4 and the citizen from Pegland with speed 4.
2
5
202 177 189 589 102
17 78 1 496 540
2016
There are multiple possible optimal solutions. Here is one optimal solution:
Pair the citizen from Dmojistan with speed 202 and the citizen from Pegland with speed 1.
Pair the citizen from Dmojistan with speed 177 and the citizen from Pegland with speed 540.
Pair the citizen from Dmojistan with speed 189 and the citizen from Pegland with speed 17.
Pair the citizen from Dmojistan with speed 589 and the citizen from Pegland with speed 78.
Pair the citizen from Dmojistan with speed 102 and the citizen from Pegland with speed 496.
This sum yields
Jo is a blogger, specializing in the critique of restaurants. Today, she wants to visit all the Vietnamese Pho restaurants in the Waterloo area, in order to determine which one is the best.
There are
In computer science, a road network with this structure is called a tree. Here are three examples of trees:
One property that is true for all trees is that there is exactly one path that does not repeat any roads between any two points in the tree.
What is the minimal length of time that Jo needs to spend on travelling on roads to visit all of the Pho restaurants?
The first line of input contains 2 integers,
The second line of input contains
The next
For 3 of the 15 available marks,
For an additional 3 of the 15 available marks,
For an additional 3 of the 15 available marks,
For an additional 4 of the 15 available marks,
Your program should output one line, containing one integer - the minimum amount of time Jo needs to spend travelling on roads in order to visit all Pho restaurants, in minutes.
8 2
5 2
0 1
0 2
2 3
4 3
6 1
1 5
7 3
3
The path between
8 5
0 6 4 3 7
0 1
0 2
2 3
4 3
6 1
1 5
7 3
7
If Jo begins at restaurant 6, she will only need to use 7 roads. One
possible path that she can take is:
Alphonse has
If two adjacent rice balls have the same size, Alphonse can combine them to make a new rice ball. The new rice ball’s size is the sum of the two old rice balls’ sizes. It occupies the position in the row previously occupied by the two old rice balls.
If two rice balls have the same size, and there is exactly one rice ball between them, Alphonse can combine all three rice balls to make a new rice ball. (The middle rice ball does not need to have the same size as the other two.) The new rice ball’s size is the sum of the three old rice balls’ sizes. It occupies the position in the row previously occupied by the three old rice balls.
Alphonse can perform each operation as many times as he wants.
Determine the size of the largest rice ball in the row after performing 0 or more operations.
The first line will contain the integer,
The next line will contain
For 1 of the 15 available marks,
For an additional 2 of the 15 available marks,
For an additional 5 of the 15 available marks,
Output the size of the largest riceball Alphonse can form.
7
47 12 12 3 9 9 3
48
One possible set of moves to create a riceball of size 48 is to combine 12 and 12, forming a riceball of size 24. Then, combine 9 and 9 to form a riceball of size 18. Then, combine 3, 18 and 3 to form a riceball of size 24. Finally, combine the two riceballs of size 24 to form a riceball of size 48.
4
1 2 3 1
3
There are no moves to make, thus the largest riceball in the row is size 3.
You may have heard of Conway’s Game of Life, which is a simple set of rules for cells on a grid that can produce incredibly complex configurations. In this problem we will deal with a simplified version of the game.
There is a one-dimensional circular strip of
Each cell is either alive (represented by a ‘1’) or dead (represented by a ‘0’). The cells change over a number of generations. If exactly one of a cell’s neighbours is alive in the current generation, then the cell will be alive in the next generation. Otherwise, the cell will be dead in the next generation.
Given the initial state of the strip, find the state after
The first line will contain two space-separated integers
For 1 of the 15 available marks,
For an additional 6 of the 15 available marks,
For an additional 4 of the 15 available marks,
Note that for full marks, solutions will need to handle 64-bit integers. For example
in C/C++, the type long long
should be
used;
in Java, the type long
should be
used;
in Pascal, the type int64
should be
used.
Output the string of
7 1
0000001
1000010
Cell 1 and cell
5 3
01011
10100
After one generation, the configuration becomes
00011
.
After two generations, the configuration becomes
10111
.