Problem S1: Voronoi Villages
Problem S1: Voronoi Villages
Problem S1: Voronoi Villages
Problem Description
In the country of Voronoi, there are N villages, located at distinct points on a straight road. Each
of these villages will be represented by an integer position along this road.
Each village defines its neighbourhood as all points along the road which are closer to it than
to any other village. A point which is equally close to two distinct villages A and B is in the
neighbourhood of A and also in the neighbourhood of B.
Each neighbourhood has a size which is the difference between the minimum (leftmost) point in
its neighbourhood and the maximum (rightmost) point in its neighbourhood.
The neighbourhoods of the leftmost and rightmost villages are defined to be of infinite size, while
all other neighbourhoods are finite in size.
Determine the smallest size of any of the neighbourhoods (with exactly 1 digit after the decimal
point).
Input Specification
The first line will contain the number N (3 ≤ N ≤ 100), the number of villages. On the next N
lines there will be one integer per line, where the ith line contains the integer Vi , the position of
the ith village (−1 000 000 000 ≤ Vi ≤ 1 000 000 000). All villages are at distinct positions.
Output Specification
Output the smallest neighbourhood size with exactly one digit after the decimal point.
Sample Input
5
16
0
10
4
15
0 4 10 15 16
Exemple d’entrée
5
16
0
10
4
15 Sortie pour l’exemple d’entrée
3.0
0 4 10 15 16
Input Specification
The first line of input contains the number N (2 ≤ N ≤ 100). The next N lines each contain
N positive integers, each of which is at most 109 . It is guaranteed that the input grid represents a
rotated version of Barbara’s grid.
Output Specification
Output Barbara’s original data, consisting of N lines, each of which contain N positive integers.
Sample Input 1
2
1 3
2 9
Sample Input 3
3
3 7 9
2 5 6
1 3 4
Exemple d’entrée 1
2
1 3
2 9
Exemple d’entrée 3
3
3 7 9
2 5 6
1 3 4
Input Specification
The first line of input contains two integers N and M (4 ≤ N, M ≤ 100). The next N lines of
input will each contain M characters, each of which is one of the eight characters W, ., C, S, L, R,
U, or D.
There will be exactly one S character and at least one . character. The first and last character of
every row and column will be W.
For 5 of the 15 marks available, there are no cameras or conveyors.
For an additional 5 of the 15 marks available, there are no conveyors.
Output Specification
For each empty cell, print one line with one integer, the minimum number of steps for the robot to
move to this empty cell without being caught or −1 if it is impossible to move to this empty cell.
The output should be in row major order; the order of empty cells seen if the input is scanned line
by line top-to-bottom and then left-to-right on each line. See the sample outputs for examples of
row major order output.
Sample Input 2
5 7
WWWWWWW
WD.L.RW
W.WCU.W
WWW.S.W
WWWWWWW
Exemple d’entrée 1
4 5
WWWWW
W.W.W
WWS.W
WWWWW
Exemple d’entrée 2
5 7
WWWWWWW
WD.L.RW
W.WCU.W
WWW.S.W
WWWWWWW
Output Specification
Output a single integer, the number of perfectly balanced trees with weight N .
Sample Input 1
4
Exemple d’entrée 1
4
Input Specification
The first line contains four space-separated integers N , M , P , Q (1 ≤ N, M, P, Q ≤ 105 ).
Then P lines follow; the i-th one contains three space-separated integers ai , bi , ci (1 ≤ ai , bi ≤
M, 1 ≤ ci ≤ 108 ).
Then Q lines follow; the j-th one contains three space-separated integers xj , yj , zj (1 ≤ xj , yj ≤
N, 1 ≤ zj ≤ 108 ).
It is guaranteed that it will be possible to travel between any two cities using flights and/or portals.
There may be multiple flights/portals between the same pair of cities or a flight/portal between a
city and itself.
For 2 of the 15 available marks, P, Q ≤ 100 and ci = 1 for all 1 ≤ i ≤ P , and zj = 1 for all
1 ≤ j ≤ Q.
For an additional 2 of the 15 available marks, P, Q ≤ 200.
For an additional 5 of the 15 available marks, N, M ≤ 200.
Output Specification
Output a single integer, the maximum sum of energy that can be saved daily.
Sample Input 2
2 3 4 1
2 3 5
3 2 7
1 2 6
1 1 8
2 1 5
Exemple d’entrée 2
2 3 4 1
2 3 5
3 2 7
1 2 6
1 1 8
2 1 5