Professional Documents
Culture Documents
NWERC 2013 ProblemSet PostContestPresentation
NWERC 2013 ProblemSet PostContestPresentation
Absurdistan
Roads
Card Trick
Diagrams &
Tableaux
Exponential
Towers
First Date
Grachten
Highway of the
Future
Infix to Prefix
Jingle Balls
Absurdistan Roads (1/2)
Absurdistan
Roads Problem
Battle for Silver
Given shortest distances in a connected graph with N vertices and
Card Trick
edges, reconstruct the original graph.
Diagrams &
Tableaux
Exponential
Solution
Towers
Absurdistan
Roads
Solution
Battle for Silver
Infix to Prefix
Jingle Balls
Battle for Silver
Absurdistan
Roads Find all cliques in given graph: Clique Problem
Battle for Silver (NP-Complete). Note that graph is planar! Kuratowski”s
Card Trick theorem: Maximum clique size is 4. Therefore, naïve
Diagrams & approach suffices:
Tableaux
Exponential
Towers
Naïve approach
First Date
Grachten
Find all cliques of size 2 (given by all edges);
Highway of the Find all cliques of size 3;
Future
Infix to Prefix
Find All cliques of size 4;
Jingle Balls Output loot of clique that provides highest loot (not from
the largest clique)!
Card Trick
Absurdistan
Roads
? 2 ? 3 ? ? 5 ? ? ? ? 3 ? ? Q ...
Battle for Silver
Card Trick
Diagrams &
Tableaux
Exponential
Naïve approach
Towers
First Date
Try X random card configurations and calculate final card
Grachten Depending on X : either too slow or incorrect, probably both
Highway of the
Future
Absurdistan
Roads
Problem
Battle for Silver
Grachten
Highway of the
Future
Infix to Prefix
Jingle Balls
Diagrams & Tableaux (2/2)
Absurdistan
Roads
Solution
Battle for Silver
First Date
Don’t forget to prune the search tree: e.g. never put a
Grachten number < k in the kth row from the top when going from
Highway of the bottom to top
Future
Infix to Prefix
Dynamic programming: e.g. over the number of different
N
Jingle Balls
columns; a columns of height H admits H different
labelings
There even exists a closed formula takes O(N 2 ) steps to
evaluate
Exponential Towers (1/4)
Absurdistan
Roads
Some preliminaries
Battle for Silver
Card Trick
Q ni
Let n = pi , how many ways to write n as a power?
Diagrams & Q ni /g
Tableaux
let g = gcd(ni ) , and let t = pi .
Exponential
Towers Then n = tg .
First Date
Every decomposition g = u ∗ v gives rise to a
Grachten
representation of n as a power (and vice versa):
Highway of the
Future n = t u∗v = (t u )v
Infix to Prefix
Jingle Balls
Exponential Towers (2/4)
Absurdistan
Roads
And now for the problem
Battle for Silver
c
Card Trick
Let n = a b , let g be the gcd of the exponents of a, and
Diagrams &
Tableaux let a = x g ,
c
Exponential
Towers
then n = x g∗b , let B = g ∗ b c , so n = x B . Forget about
First Date
x.
Grachten B can be huge, but its prime decomposition is easily
obtained: B = pkBk .
Q
Highway of the
Future
Infix to Prefix
Jingle Balls
Exponential Towers (3/4)
Absurdistan
Roads
Algorithm
Battle for Silver
Card Trick
n = x B , then every decompositionw B = u ∗ v w (v , w > 1)
gives a representation n = (x u )v , or more
Diagrams &
Tableaux
First Date
tower of powers.
Grachten For every w > 1, w ≤ max (Bk )
Highway of the
Future
for every prime pk count the decompositions
Infix to Prefix
pkBk = pkuk ∗ pkw ∗vk , so Bk = uk + w ∗ vk . So we have to
Jingle Balls count the number of multiples of w up to Bk (including 0),
and this equals [Bk /w ] + 1.
...
Exponential Towers (4/4)
Absurdistan
Roads
Algorithm
Battle for Silver
Card Trick
...
Diagrams &
Tableaux The number of representations for this w equals
Q
Exponential
Towers
([Bk /w ] + 1), v = 1 is not allowed, however, so the
actual count for this w is: ([Bk /w ] + 1) − 1.
Q
First Date
Jingle Balls
(recursively) the number of representations of s.
Sum over all w > 1, w ≤ max (Bk ).
First Date (1/2)
Absurdistan
Roads
The Hard Way: O(1), but complicated
Battle for Silver
Card Trick
Implement JulianDateToDayNr() and
Diagrams &
Tableaux DayNrToGregorianDate().
Exponential
Towers
Calculate
First Date
DayNrToGregorianDate(JulianDateToDayNr(Y, M, D)
Grachten + 1).
Highway of the
Future
However, DayNrToGregorianDate() is quite complex!
Infix to Prefix You can avoid much of the complexity by using the
Jingle Balls standard library: GregorianDate class in Java, or
gmtime() function in C/C++.
First Date (2/2)
Absurdistan
Roads
The Easy Way: O(1) by building a LUT
Battle for Silver
Card Trick
Walk all dates in the interval (approx. 3 million).
Diagrams &
Tableaux Keep track of the Julian date and the Gregorian date of the
Exponential
Towers
next day; build a lookup table.
First Date You only need to implement a ‘proceed-to-next-day’ for the
Grachten Julian and Gregorian calendars, which is easy.
Highway of the
Future
Infix to Prefix
Other algorithms are also possible, e.g. careful bookkeeping
Jingle Balls of the number of skipped dates.
Grachten
Absurdistan
Roads
Card Trick
Diagrams &
Tableaux
Exponential
Towers
First Date
Grachten
Highway of the
Future
Absurdistan
Roads
Problem
Battle for Silver
Card Trick
Given a collection of line segments, find the number of line
Diagrams &
segments going through the point in which the maximum
Tableaux
number of line segments intersect.
Exponential
Towers
Highway of the
Car speed (integer, 1 ≤ v ≤ 100), integer start times, and
Future length of highway (100) severely limit the amount of
Infix to Prefix
possible collisions over a large collection of cars.
Jingle Balls
Collisions are not always on integer coordinates.
Highway of the Future (2/2)
Absurdistan
Roads
Solution
Battle for Silver
Card Trick For each car: consider all cars which arrive earlier than this
Diagrams &
Tableaux
car but depart later. These are precisely the cars that it
Exponential
passes on the highway.
Towers
One list ordered by arrival, and one list ordered by
First Date
departure.
Grachten
Highway of the There are other ways to consider only the necessary cars.
Future
Some pitfalls for example:
Infix to Prefix
Two identical cars always require at least two lanes.
Jingle Balls
Intersections that are not on the highway (x < 0 or x > 100).
Infix to Prefix
Absurdistan
Roads Create a lookup table.
Battle for Silver For each substring of the input calculate the maximal and
Card Trick
minimal possible value (if this substring represents a
Diagrams &
Tableaux subexpression). Short strings first.
Exponential The values for the substring that starts at position x and
Towers
First Date
has length l are stored in an array, at position (x , l).
Grachten These values then are used to calculate the values for
Highway of the
longer strings, using these rules:
Future
max(x+y) = max(x) + max(y)
Infix to Prefix
max(x - y) = max(x) - min(y)
Jingle Balls max(-x) = - min(x)
and equivalent rules for min.
If n is the length of the string, the array to be filled has
about n ∗ n/2 elements.
Jingle Balls (1/2)
Absurdistan
Roads
Extended problem
Battle for Silver
Given a decorated tree T and integer
Card Trick
K , determine whether it is possible to
Diagrams &
Tableaux end up with exactly K balls in T such
Exponential that the balls are balanced.
Towers
Infix to Prefix
Recursive solution
Jingle Balls If K is even, put K /2 balls in left subtree and K /2 balls right.
If K is odd, try both ways: (K + 1)/2 left and (K − 1)/2 right,
or the other way around.
Jingle Balls (2/2)
Absurdistan
Roads Time complexity
Battle for Silver
Grachten
Linear time algorithm
Highway of the
Future
Infix to Prefix
Any subtree needs to consider at most two different values
Jingle Balls K.
Subtrees at depth d of the tree:
consider K = bB/2d c and K = dB/2d e
Or use memoization.