Input is the matrix A of N by N non-negative integers.
A distance between two elements Ai j and
Ap 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 N2 integers, representing the matrix
row-by-row.
Output file format
Output file must contain N2 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 (x1, y1),
and the second half — at (x2, y2).
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
L1, L2, … Lk
— lengths of pipe segments available and
C1, C2, … Ck
— 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
x1y1x2y2k
followed by 2k integers
L1L2 … LkC1C2 … Ck
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 (x1, y1), … (xN, yN).
It also has a property that xi < xi + 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 x1y1… xNyN.
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
A1, ..., AN by
the following method: if there are strings
Ai =
ai,1ai,2...ai,p
and
Ai + 1 =
ai+1,1ai+1,2...ai+1,q
such that for some j ≤ min(p, q)
ai,1 = ai+1,1,
ai,2 = ai+1,2, ...
ai,j = ai+1,j,
then the second string is stored as
[j]ai+1,j+1ai+1,j+2...
ai+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 A1 ... AN
Output file format
Output file must contain a single integer — minimal total length of
compressed strings.