Analysis Translated
Analysis Translated
Page 1
Problem A. Altitude
The idea of the problem: Elena Andreeva. Development: Oleg Khristenko.
This task required in a looped sequence of distinct numbers a 1, a 2, ..., a n
select three positions (i, j, k), such that a i <a j, a j> k and the sum of a distance from i to j, and by
j to k when moving clockwise minimal. A key element of the problem is
All conditions of the various elements of the sequence, so as always j
You can take the maximum element of the sequence, and in kachesvto i and j to k, and the first
j, respectively, after the first, that is, i = (j - 1) mod n and k = (j + 1) mod n.
The value of the objective function in the response of this type is 2, which is the minimum impact
ble value, and hence optimum response.
Problem B. Blocking Buffer
The idea of the problem: Andrew Shestimerov. Development: Oleg Khristenko.
In solving the problem the first thing we note the following fact:
Consider the amount of data stored in the buffer and not yet read from there. AT
any time the size of these data a multiple of GCD (r, w)
This is true, since all recorded and a few blocks of a multiple of this number.
We recalculate the number of inputs as follows:
r
w
l
r=
,r=
Gcd (r, w)
Gcd (r, w) , l = Gcd (r, w)
Now r and w vzaimoprosty. L buffer size, in turn, could be a multiple of GCD (r, w),
but that the rest of us could never fill, so a new l rounded down.
From the definition it follows that if a deadlock occurs in the buffer is now less than r
(i.e., not greater than r-1), and at the same time is more than l-w (that is, not less than l-w + 1).
It turns out that deadlock can only occur if the following inequality for
some x:
https://translate.googleusercontent.com/translate_f
1/10
11/12/2016
l-w+1xr-1l-w+1r-1r+w-2l
Now we show that if the latter condition is satisfied, then the deadlock is always possible to achieve.
We will perform the following actions:
read from the buffer block size r as long as possible
1
Page 2
write to the clipboard is exactly one block of size w
as long as we do not come in deadlock. It's always going to happen, because otherwise at some point
in the buffer have exactly r - 1 (which is the deadlock on the inequality r - 1 + w> l). Since r and
w vzaimoprosty and in fact many times we simply add the w modulo r, it will be in the buffer
achieved all residues modulo r, including r - 1
Total, the problem boils down to the entrance to divide all the numbers on the GCD (r, w) and then
verify the inequality r + w - 2 l
Problem C. Catch Me If You Can
The idea of the problem: Alexander Khokhlov. Development: Oleg Khristenko, Dmitry Zhukov.
Let Carl is initially at point A, and Pokemon is sitting at P.
Karl can make a mistake with the first direction (going into the outer half-plane of the border
3R), but the second step in exactly the opposite direction would lead him to the first results
tive movement hit to point B. If you have not been selected will lead the direction of
tangent to the outer circumference at the point A. Then, just move in the orthogonal eg
board (half-desired two attempts to guess) point P is on this
a straight line (since the radius of the point of tangency perpendiuklyaren tangent).
If point B is located on the boundary of 3R, the next move is to get back
not in the half-plane; thus, remain two turns, the latter of which must have
fall within the required range from Pokmon. If the second direction is selected
arbitrarily, the two moves may not be enough if obtained as a result of point C is located
on the border 2R, in some cases, two options may remain for a point P (which
constructed as the intersection of the perpendicular to AB and Apollonius circle for
segment BC and the ratio of 3/2), and one course for review.
Therefore, if point B is located on the boundary of 3R, the next move is
a very small angle (the author is 0.01 degrees); if the answer is zero, then we make a move on
direction, symmetric with respect to AB. If the resulting point C is located on the
border 3R, then construct a point P as the intersection of two midperpendiculars. If the point
C is located on the border of 2R, the chord AB is close enough to the border to 2R
to C point it was at a distance of less than R / 10 from the perpendicular to the
chord AB, so that, moving along the normal to the direction of the first turn, we get the desired
radius.
If the point B is located on a circle with a radius of 2R, we continue moving in the same
direction, receive a response 0 (if AB
tangent to the circle with a radius
2R), 2 or 1. In the first case, there are two possible directions orthogonal to AB from point
https://translate.googleusercontent.com/translate_f
2/10
11/12/2016
B, in the second build the intersection of the perpendicular to BC with the circle of Apollonius
for AB and 3/2, the third cross the two circles of Apollonius for AB and 3/2 for BC
and 2/1. In all cases, we have two options for the direction, and symmetrical with respect AB
the remaining two turns out to choose the right, enough.
Problem D. Demolition Time
The idea of the problem: Vasily Astakhov. Development: Vasily Astakhov Dmitry Zhukov.
2
Page 3
String before executing any deletions we denote s, after all
Deletion as a t, a pattern that we are looking for a h. The sequence a 1 <a 2 <... <a k
means to remove elements of the position, function of f (i) denotes the number of characters before i
inclusive, which will not be subjected to deletion. Pre add to the answer of all occurrences
Denia h line in s and all occurrences in t h, which do not coincide with any entry in s. BehindWe note that there were only entry that necessarily formed some substring
s, and any substring of t.
Let z (x) the maximum length of the substring t, starting with x positions and joint
h prefixed incident appropriate length. A p (x) denote the maximum length
substring s, ending at position x and coincides with the appropriate suffix h
length.
Carefully write out all the conditions that are required to pair (x, y) defined subCatching entry:
Of course, the appropriate length of the fragments must be large enough, ie
z (x) + p (y ) | h |.
There should be a time of disposal j, after that remove the distance
between elements must exactly equal the length of the fragment, i.e. (f (a j) - x + 1) +
(y - a j) = | h |.
and z (x), and p (y) must reach before the time j, that is, f (a j) - x + 1 z (x) and
(y - a j) p (y).
Note that the first condition is fully covered by the third, and the second condition can be
replaced by two independent j inequality as all intermediate lengths
will be present. The maximum length of the substring from the end in the x and y equals y - x, and
Minimal f (y) - x + 1.
Now compatible limits on the minimum and in maximum length with the terms of retego points. On the one hand we do not fit the moments removing large maximum j,
such that f (a j) -x + 1> z (x), and on the other it should be a moment not earlier than a minimum
j, such that y - a j + 1> p (y).
Rearranging the inequality of the two preceding paragraphs we'll get on one side of
Rhone events segment, suitable for x, while the other segment of the event, suitable for y,
https://translate.googleusercontent.com/translate_f
3/10
11/12/2016
it remains to find the number of overlapping pairs of segments that can easily be made effective
tively with such data structures like a tree lines or tree Fenwick.
Problem E. Economy Printing
The idea of the problem: Elena Andreeva. Development: Dmitry Zhukov.
Sort the array of page numbers to be printed, and we will divide it into blocks.
If the adjacent page numbers differ by more than 2, then those pages will be different
units, otherwise one. We will solve the problem independently for each block.
Let K block consists of pages to be printed (p l, ..., p r ). Then it can be
represented as a sequence A of length L = p r - p l + 1 of zeros and ones, i-th
Page 4
which element is equal to 1 if the page number p l + i want to print, and 0 - otherwise
case. Note that L <2K.
Consider what it looks like the answer. It is a union of four sets
a plurality of pages to be printed single pages, and three sets of page ranges
one set for each type (all, only even, only odd-numbered pages).
Note that the page ranges do not overlap within each set.
Consider the sequence of element A. Let its number i. Then, the desired answer Suthere exists no more than one of each type of range that starts at position number
less than or equal to i, and ends at position number greater than i. Furthermore, if
has a range of desired answer, form l-r, including all the pages, and l i, r> i, it is not
may range form 1% i i and i 2 1 2 #i such that 1 i i and i 2> i. Therefore, if you take
the desired response, and consider it in all ranges that start at position number
less than or equal to i, and ends at position number greater than i, then there are only 5
options are many types of these ranges:
the empty set,
A range of species i% i 1 2,
A range of species i #i 1, 2,
A range of species i% i 1 2 and the range of species i #i 1, 2,
A range of species i 1 - i 2.
Hence the solution of this problem by using dynamic programming.
There is a set of states, each of which is characterized by a pair of integers i prefix length
A sequence and a view of the set j, which form the bands that nachinayutsmiling in a position with a lower number, or equal to i, and ends at a position with a larger number
i. For each such state need to calculate the value equal to the minimum amount
stvu characters, of which the line will consist, which corresponds to a given set
https://translate.googleusercontent.com/translate_f
4/10
11/12/2016
pages
to print.
Here,
thenumber
event of,ofbut
not yet ended
take into
account
onlyinthe
characters
on the ranges
left endwill
of the range and dividing mark.
There is an initial state, the corresponding sequences A prefix length of 0 and PU
stoma plurality beginning of the range. We will sort out the state in order to increase
prefix length i. Then we can only accurately write down all the possible transitions between
states of the (i, j), where 0 i <L, 0 j <5 in (i + 1, j). Esli A i = 1, the start,
We finish or continue a certain range, or print a single page, or
A i = 0, then check that the i-th page misses the start of the range. If recalculation
We need to keep not only the value of the length of the answer, but also the state, from which came when
reaching a length.
The value of the length of the answer to the whole block will be in the element corresponding to the state
NIJ (L, 0), all printed pages, and no beginning, but has not yet ended range
mesons.
More remains to restore and print itself in the desired response format string.
Page 5
Problem F. Format
The idea of the problem and working Oleg Khristenko.
Paragraphs 1 and 2 are equivalent to the following problem: set using these in
the problem of the rules set S of all the symbols found in this line.
Note the following points to solve the problem (wherever used ratio Therefore
row on row, it is inserted in accordance with the conditions of the problem, that is, first, there is a comparison
tion lengths, then the lexicographical comparison).
Two characters to specify an interval of consecutive unprofitable length will be equal to two
instead of three.
Three or more consecutive character set as the interval is always beneficial. If the number
celebrates more than three characters, in the case of setting the length of the interval will be less; if
the number of characters is three, then minus 0x2C code is less than any of the permitted
codes, except for space, and thus the average is less than any of the character codes.
When building a description of the interval, beginning with a symbol permitted
A n C n with the code necessary to display as the start character code symbol interval
C n-1 + 1 where C n-1
previous alphanumeric character code. Indeed, in
Then the set described by alphanumeric characters remains the same, and
format string turns lower.
After that, we build a format string F 1
Description of S as a set of
intervals and individual letters and format string F 2
description of the set complement
S to the set of alphanumeric characters, add a second line of the sign '^'
and compare these lines in accordance with the requirements of the task.
https://translate.googleusercontent.com/translate_f
5/10
11/12/2016
Page 6
Note that except for the first and the last turn of the rest of the moves interlinked
between us is an empty place in series "walking" on the plates, and the sequence
rearrangements of a piece of pizza shape path in a directed graph (true direction
will rearrangements opposite orientation). We also note that our oriented
Vanny full graph without loops and repetitions. Thus the task of finding the optimal
solutions for (n - 1) n + 2 strokes is reduced to constructing Euler cycle fully oriented
Wann graph (plus a two course with additional plate).
Constructing Euler cycle in a complete graph could write any constructive
recursively for the case of a complete graph, or by applying a general algorithm Therefore
structure Euler cycle in a directed graph.
Problem H. Hockey Cup
The idea of the problem and the development of Alexander Kaluzhin
To solve this problem it was enough to sort out the result of the last meeting and
calculate the summary table for each such result. How many goals
washers could restrict the result of the last meeting? In the jury there is a test where the number 29,
but it could be limited to a supply of, for example, 100 washers. Also at search results
it was necessary not to forget that overtime difference of goals scored exactly 1.
After the last meeting of the expense is fixed, we start to count final
table. To do this, calculate its figures for each team: Points, victory, victory in fixed
mainly the time difference is thrown and passed washers, and finally, the number of abandoned
https://translate.googleusercontent.com/translate_f
6/10
11/12/2016
washers. First soritiruem by the number of points, select the set of commands with the same
index. If the set consists of one team - its final position is found. If
the two - organize them in a personal meeting, and then for them as determined itotractive position. If three or four teams have the same number of index
ochkoy, we arrange them together on the following parameters - victories. And just as in
the first case, the resolution sets one and two teams with the same number of wins.
And so on successively repeat the process for all five of these indicators.
If, after all the procedures for the resolution of the positions of three teams could not be determined
the relative order, then we assume that this order could be anything (since planted
Coin all teams are equal). At the same time we must not forget that the fourth team position is already
clearly defined. You can also notice that the described rules can not happen
a situation that, for all four teams are determined by their place on the coin (but decision
This problem does not affect the fact)
Further, based on the position occupied by Russia for all possible outcomes of the last match
We determine whether the team always comes out of the group and whether it could qualify from the group.
Problem I. Interesting Interactive Idea
The idea of the problem and develop: Dmitry Zhukov.
, l m, respectively, and r m
Let x i and x i
limits on the value of i (l x i
the value of the limit m (l m m r m). In early known that l x = 0, r x = n - 1, l m =
1, r m = n. After answering another query length of the interval of possible values for x i, or
l
x i r x i)
Page 7
m can be reduced. The idea of solving ask such questions in order to arrive at a situation
l m = r m.
To begin with we'll do so that the inequality x i
<L m. To do this, take,
for example, a sequence b k:
l x i = r x i,
b k = 1, k = 1
k-1
We will ask questions b 1, b 2, ... until after the next request b p does not get a response, relative
Wish by '>'. We make then the same again Asking questions b 1, b 2, ..., b q, where
b q
the first query to which no response is '>'. Note that this set of queries relative
vet '>' always means that x i = (x i-1 + a i) = (x i - 1 + a i) modm, and other responses indicate that
x i = (x i-1 + a i) - m = ( x i- 1 + a i) modm. Next will also only ask such questions,
which do not destroy this property. Let p + q = i. Now we can estimate x i and m l x i = 0,
q-1 b t) +1, r m = b p + (
q b t) - 1. In this case, the inequalities
r x i = b q - 1, l m = (
t=1
t=1
r x i <l m, l m> m
, b q < m
).
, R m <5m
(as b p < m
3
3
3
3
Next will run the algorithm, at each iteration, which will take place next
present. If r x i <l m - 1, Asking request a = l m - 1 r x i. Now r x i = l m - 1. Then two options.
If 3 (r x - l x + 1) r m - l m +1, the requests will specify a = max (1, (r m - l m + 1) / 3), or
as:
https://translate.googleusercontent.com/translate_f
7/10
11/12/2016
a = max (1, (r x - l x + 1) / 2), until you get a response other than '>'. Thus after each
response to the request updates the value of l x , r x , l m , r m .
Thus, at each iteration of the algorithm O (1) reduce the requests at least two
times the length of the interval [l x , r x ], or at least reduce by one third the length [l m , r m ].
As a result, we arrive at a situation l x = r x , l m = r m . Upon request, asked who, and famous
values x i , m restoring the value of x 0 and deduce the answer.
i
the n
Page 8
Described above can be made on the forehead using a dynamic programming
bust subpatterns in O (3 the n the n 2 ), which is not sufficiently effective solution.
Solve the problem in O (2 the n the n 2 ) can be exhausting answer, and then calculate the following values
Dynamic programming: dp [mask] whether the set can be defined by a bit mask
https://translate.googleusercontent.com/translate_f
8/10
11/12/2016
Page 9
equal to the maximum of f (G) and ans (T) for all components of such older partition.
It remains only to think of a way to implement the process described above is optimal enough
but. Note that when viewed from small component to large, it will be
look similar to Kruskal's algorithm is selected each time the minimum rib c,
connecting two different components A and B, after which they are combined in the component
T = A B, and the value of f (G) and ans (G) translated:
f (T) = max (max
a v , c) min b v
vT
vT
9/10
11/12/2016
(After
https://translate.googleusercontent.com/translate_f
10/10