Input is the matrix A of N by N non-negative integers.
A distance between two elements A_{i j} and
A_{p q} is defined as |i − p| + |j − q|.
Your program must replace each zero element in the matrix with the nearest non-zero one.
If there are two or more nearest non-zeroes, the zero must be left in place.
Input file format
Input file contains the number N followed by N^{2} integers, representing the matrix
row-by-row.
Output file format
Output file must contain N^{2} integers, representing the modified matrix
row-by-row.
The table surface is divided into N by M square cells.
Some cubes are stacked one upon another over the cells, forming towers.
For each cell the number of cubes stacked over it is given in the matrix A.
Your program must output the view of the table in ASCII graphics,
where each cube is represented as shown below:
+---+
/ /|
+---+ |
| | +
| |/
+---+
(here the characters used are '+', '-', '/', '|',
their ASCII codes are ASCII 43, 45, 47, 124)
The dot (ASCII 46) must be used as a background.
Input file format
Input file contains integers NM, followed by matrix A, row-by-row.
The first row describes the cube tower furthest from the viewer, left to right,
and the last row — nearest to the viewer.
Output file format
Output file must contain a string representation of the table view, with minimal number
of lines required to show all cubes. Each line must contain a string of equal length,
which is the minimal width required to show all cubes.
The Eastowner city is perpetually haunted with water supply shortages,
so in order to remedy this problem a new water-pipe has been built.
Builders started the pipe from both ends simultaneously, and after
some hard work both halves were connected. Well, almost.
First half of pipe ended at a point (x_{1}, y_{1}),
and the second half — at (x_{2}, y_{2}).
Unfortunately only few pipe segments of different length were left.
Moreover, due to the peculiarities of local technology the pipes can only be put
in either north-south or east-west direction, and be connected to form a straight line or
90 degree turn.
You program must, given
L_{1}, L_{2}, … L_{k}
— lengths of pipe segments available and
C_{1}, C_{2}, … C_{k}
— number of segments of each length,
construct a water pipe connecting given points, or declare that it is impossible.
Program must output the minimum required number of segments.
Input file format
Input file contains integers
x_{1}y_{1}x_{2}y_{2}k
followed by 2k integers
L_{1}L_{2} … L_{k}C_{1}C_{2} … C_{k}
Output file format
Output file must contain a single integer — the number of required segments,
or −1 if the connection is impossible.
Given the N by M matrix with elements equal either 0, 1 or 2,
There is at least one element equal to 2.
Your program must find such two (perhaps overlapping or even identical)
rectangles, that they would contain all the 2s which are in matrix, but none of the 1s.
If several solutions exist, the program must find a solution with minimal
area of joined rectangles.
For example, in the matrix
1 2 1 0
2 0 2 2
1 2 1 0
these rectangles are (2,1)-(2,3) and (1,2)-(4,2), with the combined area of 6.
Input file format
Input file contains integers N and M followed by N * M matrix elements.
Output file format
Output file must contain a single integer — the minimal area, or -1 if no solution exists
The seashore is represented by a polyline without self-intersections, described by
a sequence of vertices (x_{1}, y_{1}), … (x_{N}, y_{N}).
It also has a property that x_{i} < x_{i + 1}.
The sea is above the line, and the beach — below.
Your program must connect two vertices with a straight line not longer than L
chosen so as to maximize the beach area enclosed between that line and the shore.
The line must not intersect with the sea and may only touch, not intersect,
the shore polyline.
Input file format
Input file contains integer numbers NL,
followed by N pairs of integers x_{1}y_{1}… x_{N}y_{N}.
Output file format
Output file must contain a single floating point value — the maximum area that can be cut (it may be zero).
The area must be output exactly, i.e. without any rounding at all.
Many databases store the data in the character fields (and especially indices) using
prefix compression. This technique compresses a sequence of strings
A_{1}, ..., A_{N} by
the following method: if there are strings
A_{i} =
a_{i,1}a_{i,2}...a_{i,p}
and
A_{i + 1} =
a_{i+1,1}a_{i+1,2}...a_{i+1,q}
such that for some j ≤ min(p, q)
a_{i,1} = a_{i+1,1},
a_{i,2} = a_{i+1,2}, ...
a_{i,j} = a_{i+1,j},
then the second string is stored as
[j]a_{i+1,j+1}a_{i+1,j+2}...
a_{i+1,q}, where [j] is a single character with code j.
If j = 0, that is, strings do not have any common prefix, then the second
string is prefixed with zero byte, and so the total length actually increases.
Input file format
First line of input file contains integer number N, with following
N lines containing strings A_{1} ... A_{N}
Output file format
Output file must contain a single integer — minimal total length of
compressed strings.