Northwestern European Regional Contest 2017: NWERC 2017
Northwestern European Regional Contest 2017: NWERC 2017
Bath, November 26
2017
Problems
A Ascending Photo
B Boss Battle
C Connect the Dots
D Dunglish
E English Restaurant
F Factor-Free Tree
G Glyph Recognition
H High Score
I Installing Apps
J Juggling Troupe
K Knockout Tournament
Figure A.1: This picture has been cut up and pasted back together to solve Sample Input 1.
Our research tells us that having the climbers in ascending (non-decreasing) height order from
left to right will be most visually appealing. We must cut up the picture we have and somehow
paste it back together in this order.
Find the minimum number of cuts you need to make to put the photograph into ascending order.
Input
The input consists of:
• One line with an integer n (1 ≤ n ≤ 106 ), the number of people in the photo.
• One line with n integers h1 , . . . , hn (1 ≤ hi ≤ 2 · 109 for each i), the heights of the people
in the photograph, from left to right.
Output
Output the minimum number of cuts needed to rearrange the photograph into any one ascending
(non-decreasing) height order from left to right.
first bomb after the blast after the boss moves second bomb after the blast
Figure B.1: Example for n = 4. In this case 2 bombs are enough. Grey pillars represent pillars
where the boss cannot be hiding. The bomb is represented in black.
Input
The input consists of:
• One line with a single integer n (1 ≤ n ≤ 100), the number of pillars in the room.
Output
Output the minimum number of bombs needed to defeat the boss in the worst case.
1 2 3 4
10 11 12 5
9 16 6 13
8 7 15 14
Simone asked you to try the puzzle out, while betting you a balloon that it would be too hard.
Prove her wrong by writing a program that solves the puzzle for you!
Input
The input consists of:
• 4 lines, each with 4 integers, the numbers of the dots in the grid. The jth number on the
ith line is the number of the jth dot in the ith row of the grid of dots.
The 16 numbers in the input are all between 1 and 16 (inclusive) and pairwise distinct.
Output
Output the minimum number of line segments needed to connect all the dots in order.
Input
The input consists of:
• One line with an integer n (1 ≤ n ≤ 20), the number of words in the Dutch sentence.
• One line with n words, the Dutch sentence s.
• One line with an integer m (1 ≤ m ≤ 105 ), the number of words in the dictionary.
• m lines, each with three strings d, e and c, a Dutch word, the English translation, and
“correct” if this is the correct translation or “incorrect” otherwise.
A word consists of between 1 and 20 lowercase letters. Each word in s appears at least once
as a Dutch word in the dictionary, no word appears more than 8 times as a Dutch word in the
dictionary, and each combination of a Dutch and English word appears at most once.
Output
In case there is only a single translation of s, output one line with the translation followed by
one line with “correct” or “incorrect”. In case there is more than one translation, output
one line with the number of possible correct translations followed by “correct”, and one line
with the number of possible incorrect translations followed by “incorrect”.
Input
The input consists of:
• One line with three integers n, g, t (1 ≤ n ≤ 100, 1 ≤ g ≤ 200, 1 ≤ t ≤ 100), the
number of tables in the restaurant, the maximum group size, and the number of hours the
restaurant is open.
• One line with n integers c1 , . . . , cn (1 ≤ ci ≤ 200 for each i) giving the capacities of the
tables.
Output
Output the expected number of people in the restaurant when it closes. Your answer should have
an absolute or relative error of at most 10−6 .
2 8
15 9
2 7 15 8 9 5
Figure F.1: Illustration of Sample 1. The tree is factor-free; for example, the value of the node
marked “5” is coprime with all of the values of its ancestors, marked “9”, “8”, and “7”.
Given a sequence a1 , a2 , . . . , an , decide if it is the inorder sequence of some factor-free tree and
if so construct such a tree.
Input
The input consists of:
• One line with one integer n (1 ≤ n ≤ 106 ), the length of the sequence.
• One line with n integers a1 , . . . , an (1 ≤ ai ≤ 107 for each i), the elements of the
sequence.
Output
If there exists a factor-free tree whose inorder sequence is the given sequence, output n values.
For each value in the sequence, give the 1-based index of its parent, or 0 if it is the root. If there
are multiple valid answers, print any one of them.
If no such tree exists, output “impossible” instead.
(a) The six glyphs. (b) The first sample input. (c) Fitting triangles and hexagons to the
first sample. The triangles’ score is higher.
Figure G.1
You want to start analysing the language right away, so you need to get the text on the tablets
into some machine readable format. Ideally, you would like to use an OCR (optical character
recognition) tool for that, but you do not have one installed on your laptop and there is no
internet connection at the site.
Because of this you have devised your own scheme to digitise the ancient writings: for every
glyph on a tablet you first find a number of sample points that are in the carved out region, i.e. on
the boundary of the polygon. Based on those sample points you then calculate a score for each
of the six glyphs and mark the one with the highest score as the recognised glyph.
For a given number of corners k (3 ≤ k ≤ 8), the score is computed as follows. Two regular
k-gons are fitted to the sample points, one from the inside and one from the outside, such that
the following hold:
• Each polygon is centered at the origin, i.e. all vertices have equal distance to (0, 0).
• Each polygon has a vertex on the positive x-axis.
• The inner polygon is the largest such polygon containing none of the sample points.
• The outer polygon is the smallest such polygon containing all of the sample points.
Ainner
An example can be seen in Figure G.1(c). The score for this value of k is Aouter
, where Ainner and
Aouter are the areas of the inner and outer polygon, respectively.
Given a set of sample points, find the glyph with the highest score.
Output
Output the optimal number of corners k (3 ≤ k ≤ 8), followed by the score obtained for that
value of k. Your answer will be accepted if the absolute error does not exceed 10−6 . If several
values of k result in a score that is within 10−6 of the optimal score, any one of them will be
accepted.
Input
The input consists of:
• One line with an integer n (3 ≤ n ≤ 7), the number of players in the game.
• n lines, each with four integers a, b, c, d (0 ≤ a, b, c, d ≤ 109 ), giving the number of Cog,
Tablet, Compass, and Wildcard Science tokens of a player.
Output
For each player, in the same order they are given in the input, output the maximum score the
player may get.
Input
The input consists of:
• One line with two integers n, c (1 ≤ n ≤ 500, 1 ≤ c ≤ 10 000), the number of available
apps and the available disk space of the phone in megabytes.
• n lines, each with two integers d, s (1 ≤ d, s ≤ 10 000), the download size and storage
size of an app, in megabytes.
Output
Output one line with the maximum number of apps that can be installed. Then output one line
listing the numbers of those apps, in the order that Sandra should install them. In the case that
no apps can be installed, this line can be omitted.
The apps are numbered from 1 to n, in the order they are given in the input. If there are multiple
optimal solutions, output any one of them.
step 0
step 1
step 2
step 3
As a member of the audience, you are not impressed by this performance. However, you do
wonder how many balls each of the jugglers will have left at the end of the show.
Input
The input consists of:
• One line with a string s of length n (1 ≤ n ≤ 106 ) over the characters 0, 1 and 2. The ith
character in s represents the number of juggling balls initially held by the ith person.
Output
Output a string s of length n over the characters 0 and 1, the ith giving the number of juggling
balls the ith person has at the end of the show.
A
A or B
B
A or B or C
Champion!
D or E
Figure K.1: A tournament tree with 5 players. Players C, D, and E advance from the first round
automatically.
Every player has a rating indicating their strength. A player with rating a wins a game against a
a
player with rating b with probability a+b (independently of any previous matches played).
Laura as the organiser can order the starting line-up of players in any way she likes. What is the
maximum probability of Dale winning the tournament?
Input
The input consists of:
• One line with an integer n (2 ≤ n ≤ 4096), the total number of players.
• n lines, each with an integer r (1 ≤ r ≤ 105 ), the rating of a player. The first rating given
is Dale’s rating.
Output
Output the maximum probability with which Dale can win the tournament given a favourable
setup. Your answer should have an absolute or relative error of at most 10−6 .