0% found this document useful (0 votes)
98 views

Problem A. Alphabet Animals: Input

The document describes 4 programming problems: 1. An animal naming game elimination problem where the next animal name must start with the last letter of the previous name and cannot be previously used. 2. A minimum land area problem to construct 3 buildings of given sizes that can touch but not overlap in rectangular land. 3. A chocolate bar splitting problem to divide a bar into two piles of given sizes by repeatedly splitting horizontally or vertically. 4. A simplified dart scoring problem where darts are thrown at a board with a bullseye, double and single rings, and wedges of increasing score, and the total score is calculated.

Uploaded by

Andrés Quintero
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Problem A. Alphabet Animals: Input

The document describes 4 programming problems: 1. An animal naming game elimination problem where the next animal name must start with the last letter of the previous name and cannot be previously used. 2. A minimum land area problem to construct 3 buildings of given sizes that can touch but not overlap in rectangular land. 3. A chocolate bar splitting problem to divide a bar into two piles of given sizes by repeatedly splitting horizontally or vertically. 4. A simplified dart scoring problem where darts are thrown at a board with a bullseye, double and single rings, and wedges of increasing score, and the total score is calculated.

Uploaded by

Andrés Quintero
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Competitive Programming Network - 6th Activity July 18th, 2020

Problem A. Alphabet Animals


Source file name: animals.c, animals.cpp, animals.java, animals.py
Input: Standard
Output: Standard

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 1 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem B. Building Boundaries


Source file name: building.c, building.cpp, building.java, building.py
Input: Standard
Output: Standard

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 2 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem C. Cocoa Coalition


Source file name: cocoa.c, cocoa.cpp, cocoa.java, cocoa.py
Input: Standard
Output: Standard

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 3 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

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.

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 4 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 5 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem E. Eeny Meeny


Source file name: meeny.c, meeny.cpp, meeny.java, meeny.py
Input: Standard
Output: Standard

"Eeny meeny miny moe" is a well-known nursery rhyme in English,


used (among other things) by kids to "randomly" select members
of a team. It exists in many variations, one of which goes like this:

Eeny, meeny, miny, moe,


Catch a tiger by the toe.
If he hollers, let him go,
Eeny, meeny, miny, moe.

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).

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 6 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 7 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem F. Name Problem


Source file name: basenameProblem.c, basenameProblem.cpp, basenameProblem.java, basenameProblem.
Input: Standard
Output: Standard

Input
Output
Example
Input Output

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 8 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem G. Game of Gnomes


Source file name: gnomes.c, gnomes.cpp, gnomes.java, gnomes.py
Input: Standard
Output: Standard

The enemy and their massive army is approaching your fortress,


and all you have to defend it is a legion of guardian gnomes. There
is no hope of winning the battle, so your focus will instead be on
causing as much damage as possible to the enemy.
You have n gnomes at your disposal. Before the battle, they must
be divided into at most m non-empty groups. The battle will then
proceed in turns. Each turn, your gnomes will attack the enemy,
causing one unit of damage for each living gnome. Then the enemy
will attack by throwing a lightning bolt at one of the m groups. The
lightning bolt kills k of the gnomes in that group, or all of them
if the number of living gnomes in the group is less than k . The
Picture by Danielle Walquist Lynch
battle ends when all gnomes are dead. The enemy will always throw
via flickr, cc by
the lightning bolts in an optimal way such that the total damage
caused by the gnomes is minimized.
Now you wonder, what is the maximum amount of damage you can cause to the enemy if you divide the
gnomes into groups in an optimal way?
For example, if as in Sample Input 1 you have n = 10 gnomes that are to be divided into m = 4 groups,
and the lightning bolt does at most k = 3 damage, then an optimal solution would be to create one large
group of size 7 and three small groups of size 1 . In the first round, you cause 10 damage and the lightning
bolt reduces the large group by 3 . In the next round, you cause 7 damage and the large group is reduced
down to size 1 . In the remaining four rounds you do 4, 3, 2, and 1 damage respectively and the lightning
bolt removes one group each round. In total you do 10 + 7 + 4 + 3 + 2 + 1 = 27 damage.

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 9 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem H. Hot Hike


Source file name: hike.c, hike.cpp, hike.java, hike.py
Input: Standard
Output: Standard

In order to pass time during your vacation, you decided to go on a


hike to visit a scenic lake up in the mountains. Hiking to the lake
will take you a full day, then you will stay there for a day to rest and
enjoy the scenery, and then spend another day hiking home, for a
total of three days. However, the accursed weather this summer is
ridiculously warm and sunny, and since severe dehydration is not at
the top of your priority list you want to schedule the three-day trip
during some days where the two hiking days are the least warm. In
particular you want to minimize the maximum temperature during
the two hiking days.
Given the current forecast of daily maximum temperatures during
your vacation, what are the best days for your trip?

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 10 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem I. Incremental Induction


Source file name: iInduction.c, iInduction.cpp, iInduction.java, iInduction.py
Input: Standard
Output: Standard

The Nordic Collegiate Pong Championship (NCPC) is an insanely


competive tournament where every contestant plays exactly one
game of Pong against every other contestant. The last game of
the tourna- ment just finished, so only one item now remains on
the programme: the traditional diploma ceremony, where all this
year’s participants get inducted into the NCPC Hall of Fame.
According to the ancient customs, contestants who have not been
inducted into the Hall of Fame yet (the pathetic nobodies) must
stay on the left side of the stage, whereas contestants who have
been inducted (the awesome legends) must be on the right side of
the stage. Then, when a contestant is receiving their diploma, they
will symbolically walk from the left to the right side of the stage and
thus become an awesome legend. Only one contestant is inducted
into the Hall of Fame at a time, and every contestant starts on the
Pong via Wikimedia Commons,
left side initially.
public domain
The NCPC Head of Jury believes it reflects badly on her if too
many of the awesome legends on the right have lost matches against
pathetic nobodies on the left, but she quickly realizes that it might be impossible to avoid this at every
point in time during the diploma ceremony. However, she certainly wants to keep such atrocities at a
minimum. Specifically, she wants to find the smallest number k for which there exists an order of handing
out diplomas to the contestants, such that at no point there were more than k games played where an
awesome legend lost against a pathetic nobody.

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 11 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem J. Name Problem


Source file name: basenameProblem.c, basenameProblem.cpp, basenameProblem.java, basenameProblem.
Input: Standard
Output: Standard

Input
Output
Example
Input Output

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 12 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem K. Keyboard
Source file name: keyboard.c, keyboard.cpp, keyboard.java, keyboard.py
Input: Standard
Output: Standard

Consider a simplified keyboard consisting of the 26 lowercase letters as illustrated below:

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 13 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem L. Name Problem


Source file name: basenameProblem.c, basenameProblem.cpp, basenameProblem.java, basenameProblem.
Input: Standard
Output: Standard

Input
Output
Example
Input Output

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 14 of 15
Competitive Programming Network - 6th Activity July 18th, 2020

Problem M. Name Problem


Source file name: basenameProblem.c, basenameProblem.cpp, basenameProblem.java, basenameProblem.
Input: Standard
Output: Standard

Input
Output
Example
Input Output

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 15 of 15

You might also like