Problemset RPC04
Problemset RPC04
Input
The input consists of:
Torturing data. CC BY
by Timo Elliott on timoelliott.com
• One line with three integers n, k, and x (2 ≤ n ≤ 1500,
1 ≤ k ≤ 4, k < n, |x| ≤ 109 ), the number of samples,
the number of samples that may be removed, and the
average you think looks the nicest.
Output
Output the minimal absolute difference between x and the average you can obtain by removing at most
k samples from the dataset.
Your answer should have an absolute error of at most 10−4 .
Example
Input Output
5 2 2 0
1 2 3 100 200
5 4 -5 0.5
-6 -3 0 6 3
4 1 4 0.333333333333333
1 3 3 7
Problem B. Bellevue
Source file name: Bellevue.c, Bellevue.cpp, Bellevue.java, Bellevue.py
Input: Standard
Output: Standard
As any photographer knows, any good sunset photo has the sun setting over
the sea. In fact, the more sea that is visible in the photo, the prettier it is!
You are currently visiting the island Bellevue, and you would like to take a
photo of either the sunrise to the east or the sunset to the west to submit it to
Bellevue’s Astonishing Photography Competition. By carefully studying the
topographic maps, you managed to find the east-west profile of the island.
Now you would like to know the maximal amount of sea that you could
capture in a photo, measured as the viewing angle covered by water.
The profile of the island is given as a piecewise linear function consisting of
n − 1 segments between n points. The island starts and ends at sea level. As
an example, Figure 1 shows the profile of the first sample case.
Note that the viewing angle of your lens is not large enough to capture the
ocean to the east and west of the island in one shot. Also, the viewing angle
Sunset over the Mediterranean sea.
of sea at sea level is 0 degrees. CC0 by Ragnar Groot Koerkamp
Figure 1: The east-west profile of the island in the first sample case.
Input
The input consists of:
• n lines with two integers xi and yi (0 ≤ xi , yi ≤ 50 000), a point in the east-west profile of the island.
It is guaranteed that the points are given from left to right (x1 < x2 < · · · < xn ) and that the island
starts and ends at sea level (y1 = yn = 0). The interior of the island is all above sea level (yi > 0 for
1 < i < n).
Output
Output the maximal viewing angle of sea you can see, in degrees.
Your answer should have an absolute error of at most 10−6 .
Example
Input Output
6 45
0 0
2 1
3 1
4 4
5 1
9 0
5 63.4349488
1 0
5 4
6 1
8 2
9 0
A company wishes to purchase a square-shaped cleaning robot to clean a rectangularly shaped room.
Some parts of the room are obstructed.
There are different robots of different sizes. Each robot can move horizontally and vertically in the room if
no part of the robot intersects an obstruction. They are incapable of changing orientation, so movements
are always axis-aligned. Larger robots will get the job done faster, but are more likely to be hindered by
obstructions. The robot must always remain fully in the room with no portion extending past the edges
of the rectangle.
What is the largest robot the company can buy that will be able to clean all the squares of the room not
occupied by obstructions?
Input
The first line of input contains three integers n, m (3 ≤ n, m and n · m ≤ 5 · 106 ) and k (0 ≤ k < n · m,
k < 106 ), where n and m are the dimensions of the room in inches, and k is the number of obstructions.
Each of the next k lines contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m). This specifies that the
one-inch square at (i, j) is obstructed. All obstructed squares are distinct.
Output
Output a single integer, which is the maximum length of one side of the largest square-shaped robot that
could clean the entire room, or −1 if no such robot could clean the entire room.
Example
Input Output
10 7 1 2
8 3
After struggling with this one problem for days, you have had enough! You are determined to find the
bug in your algorithm once and for all! To do so, you will start all over. From scratch. At least you are
sure you know the correct answer in the most trivial case: the answer in (0, 0, . . . , 0) is 0.
You will re-solve the problem, which takes k parameters, using n simpler but slower algorithms. Each
algorithm has two bounds for every parameter i (Li and Hi ). An algorithm is only fast enough to run
on inputs (x1 , . . . , xk ) where xi ≤ Hi for all parameters i. You are confident the implementation of an
algorithm is correct if you can verify its correctness at least once on an input (x1 , . . . , xk ) where xi ≥ Li
for all parameters i. To do so, you will need another algorithm that you already proved to be correct and
can handle such large inputs, or your knowledge of the answer for (0, 0, . . . , 0).
Given a list of algorithms and their bounds, find the number of algorithms you are sure are correctly
implemented.
As an example, consider the first sample case shown in Figure 2 on the left. The first algorithm (red,
bottom left) can be used to verify the correctness of the second (yellow, top left) and third (blue, bottom
right) algorithms. No algorithm can be used to verify the correctness of the fourth algorithm (grey, top
right).
Figure 2: The algorithms to be tested in examples 1 and 2, respectively. The boxes indicate the
parameters where an algorithm must be tested, while the lighter background indicates the region where
an algorithm can be used to verify other algorithms.
Input
The input consists of:
• One line with two integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ 10), the number of algorithms to test
and the number of parameters.
• Then follow n pairs of lines:
– One line with k integers Li , . . . , Lk (0 ≤ Li ≤ 109 for all i).
– One line with k integers H1 , . . . , Hk (0 ≤ Hi ≤ 109 for all i).
It is guaranteed that Li ≤ Hi for all 1 ≤ i ≤ k.
Output
Output the number of algorithms of which you can verify the correctness.
Example
Input Output
4 2 3
0 0
4 3
1 2
4 6
3 1
7 2
6 4
8 5
4 2 4
0 0
4 3
0 2
5 5
7 1
8 2
5 5
8 6
3 1 3
1
10
10
100
0
1
3 3 0
0 0 1
2 2 1
1 0 0
2 3 4
0 1 0
3 4 5
Input
The input consists of:
• One line with a two integers n and x (1 ≤ n ≤ 105 , 0 ≤ x ≤ 106 ), the number of amplitudes and
the average perceived loudness to achieve.
Output
Output one line containing n numbers, the renormalised amplitudes with an average perceived loudness
of x.
Your answers should have an absolute error of at most 10−6 .
Example
Input
5 6
0 1 -2 3 -4
Output
0 1 -2 3 -4
Input
4 1
1 3 3 7
Output
0.242535625 0.7276068751 0.7276068751 1.697749375
Ahoy! You are sailing towards the next “Boats Are Pretty Cool” convention to sell your latest gadget: a
new type of compass.
On a normal compass, it is difficult to read off the precise wind direction. However, your new type of
compass lets you read off wind directions to a much higher precision! The display can display strings of
at most 1000 characters.
Unfortunately, you have encountered some bad weather. After a few hours of heavy winds and big waves,
you can finally look at your compass again. You read off the wind direction X you are going and know
in which wind direction Y you need to go. However, to make the ship turn you have to enter the degrees
of the angle the ship has to make in the control system. What is the smallest turn, in degrees, you have
to make to get back on the right course?
The conversion of a wind direction to degrees goes as follows. The
four basic wind directions are N, E, S, and W pointing at 0, 90, 180,
N
and 270 degrees, respectively. There are also four wind directions NNW NNE
consisting of two letters: NE, SE, SW, and NW, pointing at 45, NW NE
135, 225, and 315 degrees, respectively.
WNW ENE
A wind direction can also consist of k ≥ 3 letters l1 l2 . . . lk . In that
case, the last two letters indicate one of the four two-letter wind W E
directions, i.e., lk−1 lk ∈ {NE, SE, SW, NW} and the other letters
are equal to one of these, i.e., li ∈ {lk−1 , lk } for all i ≤ k − 2. This WSW ESE
wind direction points precisely in the middle of the following two
wind directions: SW SE
SSW SSE
S
• wind direction l2 . . . lk ,
SSSE
• the first wind direction of at most k − 1 letters you encounter
when starting in l2 . . . lk and move along the circle towards l1 . Figure 3: Wind directions
For example, the wind direction SSSE points in the middle of SSE and S, because S is the first wind
direction with at most 3 letters when moving from SSE towards S, as can also been seen in Figure 3.
Input
The input consists of:
• One line with two strings X and Y (1 ≤ |X|, |Y | ≤ 1000), indicating the wind directions as described
above.
Output
Output the smallest turn you have to make to go from direction X to Y .
Your answer should have an absolute error of at most 10−6 .
Example
Input Output
N S 180
NNE SSSE 146.25
ENE NW 112.5
Input
The input consists of:
• One line with two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 8), the number of pieces of gravel and
the capacity per grid cell.
• One line with n integers w1 , . . . , wn (1 ≤ wi ≤ 106 for all i), the weight of each piece of gravel.
Output
Output the minimal number of times a stone needs to be split into two, such that all the pieces of gravel
can be used to fill all the grid cells perfectly.
Example
Input Output
5 8 1
2 4 5 6 7
2 5 4
12 13
-2 -1 0
1
2
3
4
5
Input
The input consists of:
• One line with n integers x (|x| ≤ 109 ), the position of each box. The box positions are ordered
non-decreasingly.
Output
Output the minimal time to reprogram the parcel retriever robot for an optimal moving of boxes.
Example
Input Output
7 8
-1 -1 3 3 3 3 4
8 24
2 2 2 2 2 2 4 4
Input
The input consists of:
• One line containing two integers, n (1 ≤ n ≤ 105 ) the num- CC0, source: freesvg.org/girl-skating
Output
Output a line with k integers c1 , . . . , ck , where cj is the number of days that person j can skate on the
ice at the end of the day.
Example
Input Output
3 2 1 0
-3 1 -7
1 2
5 3 4 2 0
-5 -5 15 -5 -5
1 2 3
You have just gotten a new job at the Bathroom Accessories Production Company.
The first task you are given is to jab holes into showerheads. To prove yourself,
you have decided you want to create as many holes as possible.
However, you cannot just randomly drill holes everywhere in the showerhead.1
In order to ensure that the showerheads look aesthetically pleasing, the company
has composed some guidelines which you will have to follow. See Figure 5 for
some examples of aesthetically pleasing showerheads.
• The distance between the centers of any two holes should be at least e. CC BY 3.0 by gratuit on
freeimageslive.co.uk
Figure 5: Possible aesthetically pleasing showerheads for the first two examples.
Input
The input consists of:
• One line with two integers n and e (1 ≤ n, e ≤ 104 ), the number of circles and the minimal distance
between holes.
It is guaranteed that the numbers ri are given in increasing order, and that ri+1 − ri ≥ e. Furthermore,
it is guaranteed that increasing any radius ri by at most 10−6 will not change the final answer.
Output
Output the maximal number of holes that you can make in the showerhead.
1
At least, not without getting fired.
Example
Input Output
4 1 104
2 3 5 7
2 2 21
2 5
3 20 44
14 53 80
Input
The input consists of:
• One line with three integers a, b, and c (1 ≤ a < b < c ≤ 1000), the cost of letting the wool strand
through the back unused, the cost of using the wool in a stitch, and the cost of starting or ending
the use of a colour of wool.
• One line with a string w (1 ≤ |w| ≤ 26), representing the unique letters used for denoting stitch
colours.
• One line with a string p (1 ≤ |p| ≤ 106 ), representing the stitch colours of the knitting pattern.
Output
Output, for every colour of wool, in the order as they are in w, the amount of wool used in this pattern.
2
Most real-life knitting patterns are two-dimensional, but since you zig-zag through such a pattern while knitting, the
input is one-dimensional for simplicity.
Example
Input Output
1 2 4 36
rgb 22
rrrrrgbgbgbgbgbrrrrr 22
2 4 1000 2024
ab 2032
abbbbbbbba
Output
Output the length of one of the sides of the cube-shaped container that will contain all the BAPC liquid.
Your answer should have an absolute error of at most 10−6 .
Example
Input Output
3 42
21 28 35
3 2200.6131345362505
22.10 2022 1337
3 3.777901284526486
1.41421356 2.718281828 3.1415926535