Problem A. Alphabet Animals: Input
Problem A. Alphabet Animals: Input
You are playing a game in which a group of players take turns saying
animal names. The animal name you say when it is your turn must
start with the same letter as the previously said animal ends with
and it must not have been said previously in this round of the game.
If there is no valid name or you cannot come up with one you are
eliminated.
Given the last animal name said before your turn and a list of all
names not yet used, can you make it through this turn? If so, can
you make sure to eliminate the next player?
Input
The first line of input contains a single word, the animal that the
previous player just said. The next line contains a single integer n
(0 ≤ n ≤ 105 ), the number of valid unused animal names. Each
of the following n lines contains one valid unused animal name. Solution to Sample Input 1 by Kuebi
All animal names (including the one the previous player said) are via Wikimedia Commons, cc by-s
unique and consist of at least 1 and at most 20 lower case letters
’a’-’z’.
Output
If there is any animal name you can play that eliminates the next player, output the first such name from
the input list, followed by an exclamation mark. Otherwise, if there is any animal name that you can
play, output the first such name. Otherwise, output a question mark (in this case you will just have to
make up a fake name in the hope that the others will trust you that this is a real animal).
Example
Input Output
pig goat
2
goat
toad
dog ?
2
snake
emu
hare eagle!
3
bee
cat
eagle
Maarja wants to buy a rectangular piece of land and then construct three buildings on that land. The
boundaries of the buildings on the ground must have rectangular sizes a1 × b1 , a2 × b2 , and a3 × b3.
They can touch each other but they may not overlap. They can also be rotated as long as their sides are
horizontal and vertical. What is the minimum area of land Maarja has to buy?
Figure B.1: Illustration of the two test scenarios in Sample Input 1 and their solutions. In the second
scenario the 5 × 1 building has been rotated by 90 degrees.
Input
The input consists of multiple test scenarios. The first line of input contains a single integer t
(1 ≤ t ≤ 1000), the number of scenarios. Then follow the t scenarios. Each scenario consists of a
single line, containing six integers a1 , b1 , a2 , b2 , a3 and b3 (1 ≤ a1 , b1 , a2 , b2 , a3 , b3 ≤ 109 ).
Output
For each test scenario, output the minimum area of land such that Maarja can construct the three
buildings.
Example
Input Output
2 12
2 3 2 2 1 1 21
2 4 5 1 2 3
Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate cells.
They decide that Alice should get a < n · m pieces and that Bob should get b = n · m − a pieces. To
split the chocolate bar, they repeatedly take a single piece of chocolate and break it either horizontally or
vertically, creating two smaller pieces of chocolate. See Figure C.1 for an example.
What is the minimum number of splits that Alice and Bob need to perform in order to split the n-by-m
chocolate bar into two piles consisting of a and b chocolate cells?
Figure C.1: Illustration of a solution to Sample Input 2, showing the original 10-by-10 chocolate bar split
three times into pieces of size 10-by-2, 10-by-5 , 3-by-3 and 7-by-3 . Giving Alice the 10-by-5 and 7-by-3
pieces, she gets a total of 50 + 21 = 71 chocolate cells.
Input
The input consists of a single line, containing the three integers n, m and a (1 ≤ n, m ≤ 106 , 1 ≤ a < n·m).
Output
Output the minimum number of splits needed to achieve the desired division of chocolate.
Example
Input Output
3 10 9 1
10 10 71 3
Problem D. Darts
Source file name: darts.c, darts.cpp, darts.java, darts.py
Input: Standard
Output: Standard
A staple to many game rooms, darts is a fun game that doesn’t require a lot of physical space. The
standard dartboard (see Figure 1) consists of 6 concentric rings and 20 wedges, dividing the board into a
number of regions, each with well-defined scores (note: for a higher picture resolution/clarity, fewer than
20 wedges are depicted in Figure1). The centermost ring is scored as a double bullseye, while the second
ring gives the score of a single bullseye. Beyond the second ring, each wedge has a score between 1 and
20 with the spaces between certain rings having double and triple score modifiers. A new, simpler version
of the game is being proposed to attract younger players to the game.
The simpler version of the game is illustrated in Figure 2. More specifically, the board consists of exactly
3 (instead of 6) concentric rings and it may have fewer (instead of exactly 20) wedges. Also, in the
simpler board, the wedges are of equal size. The scoring for this simple version is as follows:
Assume the board is centered at the origin (“0,0” in Cartesian plane). Let w refer to the number of
wedges on the board (8 in Figure 2), and let b, d, s refer to (respectively) the radii of the smallest, second
smallest, and the largest rings.
The wedge immediately above the positive x axis (Wedge 1 in Figure 2) is scored at 1 point and the score
for each wedge is increased by 1 in a counterclockwise fashion, thus resulting in the wedge below the
positive x axis (Wedge 8 in Figure 2) having a score of w. The area within the circle centered at the origin
with radius b represents the bullseye and is always scored at 50 points. The area between radii b and d
denotes the double ring and any dart landing within the double ring is scored at twice the value of the
surrounding wedge. The area between radii d and s denotes the single ring and any dart landing within
the single ring is scored at the value of the surrounding wedge. Any dart landing outside the dartboard
carries a score of zero (0).
Given the description (layout) of such a board centered at the origin and a number of dart throws, you
are to calculate the total score.
Input
The first input line contains a positive integer, n, indicating the number of test cases to process. Each test
case will contain multiple input lines. The first line of each test case will contain four integers separated
by a space: w (2 ≤ w ≤ 20), representing the number of equal-sized wedges on the board, followed by
b, d, s (0 < b < d < s < 100), representing the radii of the bullseye, double ring and single ring regions
of the board. The second input line of each test case will contain an integer, t (1 ≤ t ≤ 100), indicating
the number of dart throws. Each of the following t input lines contains two floating point numbers (three
decimal places), x and y (−100 ≤ x, y ≤ 100), providing the Cartesian coordinates of a dart throw.
Assume that no dart will land within 10-5 of any boundary (line or arc/curve).
Output
For each test case, output a single integer on a line by itself indicating the total score for all dart throws.
Example
Input Output
3 58
4 7 13 10 0
2 73
4.000 4.000
6.000 -4.000
10 1 6 10
1
20.000 -0.500
8 3 7 50
5
-0.750 1.207
1.180 3.132
27.111 -44.630
-43.912 -22.104
2.000 -6.000
Similar verses exist in most languages, such as "Ulle dulle dof" in Picture by Gina Harbach Glenn
Finnish, "Akka bakka bonka rakka" in Norwegian, and "Ole dole Green on Flickr, cc by-nd
doff" in Swedish.
Two teams are to be selected for a game and the rhyme is used to
select one kid for a team at a time, alternating between the two
teams, until all kids have been selected. The kids are standing in a circle. In each selection round we start
counting the kids in clockwise order around the circle, skipping one kid for every word in the rhyme, until
the last word. The kid matching the last word is chosen for the current team and then the next round
starts. In all rounds but the first, the counting starts at the next remaining kid (in clockwise order) after
the one that was selected in the previous round. See Figure E.1 for an example. Given such a rhyme, and
a group of kids, can you tell which kids will be in which team?
Figure E.1: Illustration of the first three rounds of Sample Input 1. In rounds 1 and 3, Alvar and Rakel
get selected for the first team, and in round 2, Lisa is selected for the second team. In round 4 (not
shown), only Kalle remains and is selected for the second team.
Input
The first line of input contains the rhyme, consisting of a list of words separated by spaces. The second
line of input contains an integer n (1 ≤ n ≤ 100), the number of kids. Then follow the names of the kids,
one per line. The kids are given in clockwise order and the first kid listed is the one at which counting
starts in the first round.
All words and names consist only of upper and lower case letters ‘A’-‘Z’ and ‘a’-‘z’. No input line is empty
or longer than 100 characters (excluding the newline character at the end of the line).
Output
Output the two teams, starting with the one whose first member is chosen first. For each team, output
the number of kids in the team, followed by the names of the kids in the team, in the same order as they
were chosen for the team.
Example
Input Output
eeny meeny miny 2
4 Alvar
Kalle Rakel
Lisa 2
Alvar Lisa
Rakel Kalle
Every Other 2
3 b
a c
b 1
c a
Input
Output
Example
Input Output
Input
The input consists of a single line containing the three integers n , m , and k (1 ≤ n ≤ 109 , 1 ≤ m, k ≤ 107 ),
with meanings as described above.
Output
Output the maximum amount of damage you can cause to the enemy.
Example
Input Output
10 4 3 27
5 10 100 15
Input
The first line of input contains an integer n (3 ≤ n ≤ 50), the length Picture by dan lundmark on flickr,
of your vacation in days. Then follows a line containing n integers cc by
t1 , t2 , ..., tn (−20 ≤ ti ≤ 40), where ti is the temperature forecast
for the i’th day of your vacation.
Output
Output two integers d and t, where d is the best day to start your trip, and t is the resulting maximum
temperature during the two hiking days. If there are many choices of d that minimize the value of t, then
output the smallest such d.
Example
Input Output
5 2 28
23 27 31 28 30
4 1 30
30 20 20 30
Input
The first line of input contains a single integer n (1 ≤ n ≤ 5000), the number of contestants. Then follows
n − 1 lines, the ith of which contains a binary string of length i. The j th character on the ith line is 1 if
contestant i + 1 defeated contestant j , and 0 if contestant j defeated contestant i + 1.
Output
Output a single integer k, the smallest number according to the requirements above.
Example
Input Output
4 1
1
01
100
5 3
0
00
100
1100
Input
Output
Example
Input Output
Problem K. Keyboard
Source file name: keyboard.c, keyboard.cpp, keyboard.java, keyboard.py
Input: Standard
Output: Standard
We define the neighbors of a key (letter) as all the letters adjacent to it. For example, the neighbors of
‘a’ are b, k, j, neighbors of ‘b’ are a, c, l, k, j, neighbors of ‘n’ are d, e, f, o, x, w, v, m, and neighbors of
‘z’ are p, q, r, y.
Given two words consisting of lowercase letters only, you are to determine which of the following three
cases applies to them:
1. identical: this is when the two words are of the same length and they match letter-by-letter. For
example, “cool” and “cool” are identical, “cool” and “col” are not, and “cool” and “colo” are not.
2. similar: this is when the two words are of the same length, they are not identical words, and
each corresponding two letters either match or are neighbors. For example, “aaaaa” and “abkja”
are similar, “moon” and “done” are similar, “knq” and “bxz” are similar, but “ab” and “cb” are not
(because of ‘a’ in the first word and the corresponding ‘c’ in the second word).
3. different: this is when neither of the above two cases applies to the two words, i.e., they are not
identical and they are not similar. For example, “ab” and “abc” are different, “ab” and “az” are
different, and “az” and “za” are different.
Input
The first input line contains a positive integer, n, indicating the number of test cases to process. Each of
the following n input lines represents a test case, consisting of two words separated by one space. Each
word consists of lowercase letters only and will be between 1 and 20 letters, inclusive.
Output
For each test case, output one line. That line should contain the digit (number) 1, 2, or 3, to indicate
which of the above three cases applies to the two input words.
Example
Input Output
7 2
a k 1
a a 3
a z 1
cool cool 2
aaaaa abkja 3
ab abc 3
az za
Input
Output
Example
Input Output
Input
Output
Example
Input Output