0% found this document useful (0 votes)
51 views

Problemset RPC04

The document describes 4 problems for a competitive programming activity. Problem A involves adjusting the average of a data set by removing some samples. Problem B involves calculating the maximum viewing angle of the sea that can be seen from an island's east-west profile. Problem C involves finding the largest cleaning robot that can clean an obstructed room. Problem D involves determining the number of debugging algorithms that are correctly implemented by verifying their results on sample inputs.

Uploaded by

Teno notztli
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Problemset RPC04

The document describes 4 problems for a competitive programming activity. Problem A involves adjusting the average of a data set by removing some samples. Problem B involves calculating the maximum viewing angle of the sea that can be seen from an island's east-west profile. Problem C involves finding the largest cleaning robot that can clean an obstructed room. Problem D involves determining the number of debugging algorithms that are correctly implemented by verifying their results on sample inputs.

Uploaded by

Teno notztli
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Competitive Programming Network - 4th Activity April 15th, 2023

Problem A. Adjusted Average


Source file name: Adjusted.c, Adjusted.cpp, Adjusted.java, Adjusted.py
Input: Standard
Output: Standard

As a student of the Biology And Probability Course at your


university, you have just performed an experiment as part of
the practical assignments. However, your results do not look
very nice: you had hoped that the average of your samples
would be different from what it is now.
To improve your results, you decide to let some of your sam-
ples “magically disappear” (i.e., dump them in the waste
bin). In order to not raise suspicion with your teacher, you
can remove only a few of your samples. How close can you
possibly get to your desired average?

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.

• One line with n integers x (|x| ≤ 109 ), representing


the samples.

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 1 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

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:

• One line with an integer n (3 ≤ n ≤ 50 000), the number of points.

• 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 .

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 2 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 3 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem C. Cleaning Robot


Source file name: Cleaning.c, Cleaning.cpp, Cleaning.java, Cleaning.py
Input: Standard
Output: Standard

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 4 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem D. Dimensional Debugging


Source file name: Debugging.c, Debugging.cpp, Debugging.java, Debugging.py
Input: Standard
Output: Standard

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.

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 5 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 6 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem E. Equalising Audio


Source file name: Equalising.c, Equalising.cpp, Equalising.java, Equalising.py
Input: Standard
Output: Standard

As a radio engineer at the Balanced Audio Podcast c your job is to


deliver an equal listening experience at all times. You did a poll among
the listeners and they are especially concerned about fluctuations in
loudness. To resolve this you bought a transformer to equalise the
audio, but alas, its software got corrupted during transport.
Your job is to rewrite the equalising software. As input the trans-
former gets n amplitudes a1 , . . . , an , with an average perceived loud- CC BY-SA 4.0 by Rburtonresearch on Wikipedia
1 Pn
ness of n i=1 a2i . The output should contain the same amplitudes,
but renormalised by some constant positive factor, such that the average perceived loudness is x. There
is one exception: total silence should always be preserved.

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.

• One line with n integers a1 , . . . , an (|ai | ≤ 106 ), the amplitudes.

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 7 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem F. Failing Flagship


Source file name: Failing.c, Failing.cpp, Failing.java, Failing.py
Input: Standard
Output: Standard

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 .

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 8 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Example
Input Output
N S 180
NNE SSSE 146.25
ENE NW 112.5

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 9 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem G. Grinding Gravel


Source file name: Grinding.c, Grinding.cpp, Grinding.java, Grinding.py
Input: Standard
Output: Standard

During the renovation of your garden, you decide that you


want a gravel path running from the street to your front
door. Being a member of the Boulders And Pebbles Com-
munity, you want this path to look perfect. You already
have a regular grid to put the gravel in, as well as a large
container of gravel containing exactly as much as the total
capacity of the grid.
There is one problem: the gravel does not yet fit perfectly
into the grid. Each grid cell has the same (fixed) capacity
and every piece of gravel has a certain weight. You have a
grindstone that can be used to split the stones into multiple
Perfectly ground gravel in a perfect grid.
pieces, but doing so takes time, so you want to do a min- CC BY-NC 2.0 by markjowen66 on Flickr
imal number of splits such that the gravel can be exactly
distributed over the grid.
As an example, consider the first sample case. There are three grid cells of size 8, which can be filled as
follows. Put the stones of weight 2 and 6 in the first cell. Now grind the stone of weight 7 into two pieces
of weight 3 and 4. Then the other two grid cells get filled by weights 3, 5 and 4, 4 respectively.

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.

It is guaranteed that w1 + w2 + · · · + wn is a multiple of k.

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 10 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem H. Heavy Hauling


Source file name: Hauling.c, Hauling.cpp, Hauling.java, Hauling.py
Input: Standard
Output: Standard

The warehouse of the Boxes And Parcels Center (BAPC)


just received an official warning from the inspector: appar-
ently, it does not conform to the latest safety requirements.
In the past, it was allowed to stack multiple boxes at the
same shelf location, but due to the potential fire hazard,
this is no longer allowed. In a hurry, all employees of the
BAPC are roused to move the boxes to distinct positions.
After moving the boxes, the automated parcel retriever robot
needs to be reprogrammed such that it knows the correct
location of the boxes. Per box that is moved d positions,
The Parcel Retriever Robot.
it takes d2 time to do this reprogramming. Of course, the CC BY 2.0 by Enrique Dans on Flickr

BAPC should be up and running as soon as possible after


moving the boxes, so the boxes should be moved in such a way that this total reprogramming time is as
small as possible. Calculate the minimal time for the reprogramming for an optimal moving of boxes.
The warehouse of the BAPC is unbounded in both directions.
As an example, consider Figure 4, corresponding to the first example case. One box at position −1 is
moved to the left, which costs 1 time for the reprogramming. The box at position 4 is moved one position
to the right, to make place for one of the boxes at position 3, costing 1 time as well. Two boxes at position
3 are moved to the left (costing 1 and 4), and one box at position 3 is moved to the right (costing 1),
making the total cost 1 + 1 + 1 + 4 + 1 = 8.

-2 -1 0
1
2
3
4
5

Figure 4: Visualisation of the first example case.

Input
The input consists of:

• One line with an integer n (1 ≤ n ≤ 106 ), the number of boxes.

• 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.

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 11 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Example
Input Output
7 8
-1 -1 3 3 3 3 4
8 24
2 2 2 2 2 2 4 4

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 12 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem I. Ice Growth


Source file name: Icegrowth.c, Icegrowth.cpp, Icegrowth.java, Icegrowth.py
Input: Standard
Output: Standard

Ice growth is dependent on temperature. A rule of thumb is that


every 5 degrees of frost (on average in a 24-hour period) con-
tributes to 1 cm of ice growth, whilst every 5 degrees above zero
removes 1 cm of ice. For example, if there are three days with
average temperatures of −3, 1 and −7 degrees Celsius there will
be a total of 3 − 1 + 7 = 9 degrees of frost and thus 1.8 cm of ice
growth at the end of day 3. Of course, the ice thickness cannot
be negative. If there is enough ice, people can skate on it. The
required ice thickness depends on the person, as different persons
have different perceptions of safety.
There is currently no ice, but the weather report for the next n
days has just come in, and a group of k people wants you to figure
out how many of these days they can skate on the ice at the end
of the day.

Input
The input consists of:

• One line containing two integers, n (1 ≤ n ≤ 105 ) the num- CC0, source: freesvg.org/girl-skating

ber of days and k (1 ≤ k ≤ 105 ) the number of people.

• One line with n integers a1 , . . . , an (−106 ≤ ai ≤ 106 for all


i), the average temperature on day i.

• One line with k integers b1 , . . . , bk (1 ≤ bj ≤ 106 for all j),


the required minimal ice thickness in cm before person j can
skate on the ice.

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

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 13 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem J. Jabbing Jets


Source file name: Jabbing.c, Jabbing.cpp, Jabbing.java, Jabbing.py
Input: Standard
Output: Standard

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 holes should be arranged in concentric circles of radii r1 , r2 , . . . , rn : the


center of every hole should be on one of these circles.

• The distance between the centers of any two holes should be at least e. CC BY 3.0 by gratuit on
freeimageslive.co.uk

How many holes can you make at most?

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.

• One line with n integers r1 , . . . , rn (1 ≤ ri ≤ 104 ), the radii of the circles.

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.

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 14 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Example
Input Output
4 1 104
2 3 5 7
2 2 21
2 5
3 20 44
14 53 80

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 15 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem K. Knitting Patterns


Source file name: Knitting.c, Knitting.cpp, Knitting.java, Knitting.py
Input: Standard
Output: Standard

It is the most relaxing hobby of anyone’s grandma: knitting! Your


grandma uses a lot of wool, even for the most simple patterns that
she is knitting. You are sure that she can be more efficient with
her wool, so you decide to write a program that calculates the most
efficient use of wool.
A knitting pattern is a long list of stitches, where each stitch can use
a different colour.2 There is a cost for starting or ending the use of a
certain colour, for using the wool in a stitch, and for letting it strand
through the back unused. For a given knitting pattern, calculate the
least possible amount of wool required for every colour of wool.
As an example, consider the first example case. There are three
colours of wool (red, green, and blue). The red wool is used at the
start and at the end of the pattern: it is most efficient to start and Knitting Grandma.
stop using the red wool for both parts separately (4 · 4 = 16 cost), Pixabay License

and it is used in ten stitches (10 · 2 = 20 cost), giving a total cost


of 36. The green and blue wool have the same cost: start once (4 cost), use for five stitches (5 · 2 = 10
cost), strand along the back for four stitches (4 · 1 = 4 cost), and stop using the colour (4 cost), giving a
total cost of 22.

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.

All stitch colours use English lowercase letters (a-z).

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.

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 16 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Example
Input Output
1 2 4 36
rgb 22
rrrrrgbgbgbgbgbrrrrr 22
2 4 1000 2024
ab 2032
abbbbbbbba

www.facebook.com/RedProgramacionCompetitiva Twitter: @RedProgramacion


Page 17 of 18
Competitive Programming Network - 4th Activity April 15th, 2023

Problem L. Lots of Liquid


Source file name: Liquid.c, Liquid.cpp, Liquid.java, Liquid.py
Input: Standard
Output: Standard

You work at a warehouse that sells chemical products, where


somebody just placed an order for all the Boron Acetate
Phosphoric Carbonate (BAPC) that you have in store. This
liquid is stored in many separate lots, in cube-shaped con-
tainers, but your client requires the order to be delivered in
a single cube-shaped container that fits all the BAPC liquid
perfectly. What should be the size of this container?

Input Some of the cube-shaped containers.


The input consists of: Used with permission from
BeautifulChemistry.net

• One line with an integer n (1 ≤ n ≤ 105 ), the number


of cube-shaped containers that you have in store.

• One line with n floating-point numbers c


(1 ≤ c ≤ 109 ), the length of one of the sides for
each of these containers.

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

www.redprogramacioncompetitiva.com/ Twitter: @RedProgramacion


Page 18 of 18

You might also like