0% found this document useful (0 votes)
62 views16 pages

Problem C: Cocoa Coalition

The document describes a scenario where gnomes must be divided into groups to defend a fortress from an approaching enemy army, with the goal of maximizing the damage done to the enemy over multiple rounds of combat where the gnomes attack and the enemy responds with lightning bolts that kill gnomes. It asks for the maximum damage possible given numbers of gnomes, groups, and kills per lightning bolt. Sample inputs and outputs are provided as examples.

Uploaded by

Jhon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views16 pages

Problem C: Cocoa Coalition

The document describes a scenario where gnomes must be divided into groups to defend a fortress from an approaching enemy army, with the goal of maximizing the damage done to the enemy over multiple rounds of combat where the gnomes attack and the enemy responds with lightning bolts that kill gnomes. It asks for the maximum damage possible given numbers of gnomes, groups, and kills per lightning bolt. Sample inputs and outputs are provided as examples.

Uploaded by

Jhon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

NCPC19C

Problem C
Cocoa Coalition
Time limit: 1 second
Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate
cells. They decide that Alice should get a < n · m pieces and that Bob should get b = n · m − a
pieces. To split the chocolate bar, they repeatedly take a single piece of chocolate and break it
either horizontally or vertically, creating two smaller pieces of chocolate. See Figure C.1 for an
example.
What is the minimum number of splits that Alice and Bob need to perform in order to split
the n-by-m chocolate bar into two piles consisting of a and b chocolate cells?

10
7

2 5 3

Figure C.1: Illustration of a solution to Sample Input 2, showing the original 10-by-10 chocolate
bar split three times into pieces of size 10-by-2, 10-by-5, 3-by-3 and 7-by-3. Giving Alice the
10-by-5 and 7-by-3 pieces, she gets a total of 50 + 21 = 71 chocolate cells.

Input
The input consists of a single line, containing the three integers n, m and a (1 ≤ n, m ≤ 106 ,
1 ≤ a < n · m).

Output
Output the minimum number of splits needed to achieve the desired division of chocolate.

Sample Input 1 Sample Output 1


3 10 9 1

Sample Input 2 Sample Output 2


10 10 71 3

NCPC 2019 Problem C: Cocoa Coalition 5


This page is intentionally left blank.
UKIE19D
Problem D
Dome Construction

The world’s largest indoor water park is built inside a hemispherical dome that was once used as
an aircraft hangar. The park attracts more than 10 000 visitors per day and is big enough that it
even has its own tropical micro-climate with clouds forming inside.
Management would like to expand business operations by opening another branch in the dome
of your local cathedral. The micro-climate is a key selling point, so to really capitalise on the
cathedral they asked you to expand the dome’s radius so that it contains at least a given number
of clouds. A cloud is contained if its centre is on or inside the boundary of the dome.
You are a cloud engineer by trade, and hence a competent meteorologist. You already identified
several potential clouds close by and plotted them in three dimensions relative to the centre of
the current structure. In order to capture enough of them, how large do you need to make the
radius of the dome?

Input
• The first line contains the number of clouds you found, n, and the number that must be
contained, k, respectively (1 ≤ k ≤ n ≤ 105 ).
• The next n lines each contain three real numbers xi , yi , zi , the coordinates of the ith
cloud relative to the centre of the dome (0 ≤ |xi |, |yi |, |zi | ≤ 106 ). Every cloud has a
non-negative y-coordinate.

Output
Output the minimum radius of the dome required to enclose at least k points. Your answer must
be accurate to an absolute or relative error of 10−6 .

Sample Input 1 Sample Output 1


5 3 4.22374242
-4 2 1
2.1 3 5
1.2 1 -1
-2.2 3 2
1 0 2.1
This page is intentionally left (almost) blank.
Problem E UKIE19E
Estate Agent

Rupert makes a living as the only real estate agent in a small town in England. He asks for 5%
commission for every house that he sells.
Rupert organises one big auction per year. Every family (numbered from 1 to n) must participate
in this action, although making or an accepting an offer is optional. Everyone puts in bids for the
houses they would like to move to, provided they can sell their current house at the same time.
This is a very transparent process–Rupert can see exactly how much commission he will make if
he accepts the right buyers’ offers on behalf of the sellers. He may discard some offers from
buyers in order to drive up the overall commission. In fact, he might even decide to discard all
of the offers from one family and let them stay in their current home, if it makes more money
for him.
Find the maximum commission Rupert can make if he discards offers optimally.

Input
The input consists of:
• one line containing two integers n and m (1 ≤ n ≤ 150, 0 ≤ m ≤ n × (n − 1)), the
number of families on the market and the number of offers made.
• m lines, describing the offers.
The ith such line contains three integers fi , hi and ai (1 ≤ fi , hi ≤ n, fi 6= hi , 0 ≤ ai ≤
106 ), the family making the offer, the family that owns the house that the offer is for and
the amount offered.
No family makes more than one offer to the same house.

Output
Output how much Rupert will earn via commissions if he discards offers optimally. Your answer
must be accurate to an absolute or relative error of 10−6 .

Sample Input 1 Sample Output 1


4 5 1.0
1 2 3
2 3 9
3 1 5
3 2 11
4 1 6
Sample Input 2 Sample Output 2
4 5 1.45
1 2 15
2 3 9
3 1 5
3 2 11
4 1 6
Problem F UKIE19F
Feeding Seals

You are in charge of feeding the seals in the Welsh Mountain Zoo. This involves purchasing
buckets of fish and allocating them to volunteers to trek into the enclosure and distribute fairly
to the blubbery residents.
The buckets of fish are already set out. Each volunteer can be assigned to carry either one or two
of these buckets, as long as the combined weight of the buckets is small enough.
How many volunteers will you need to distribute all of the fish in one trip?

Input
• The first line contains the number of buckets to be delivered, n (1 ≤ n ≤ 105 ), and the
integer carrying capacity of a volunteer, c (1 ≤ c ≤ 109 ).
• The second line contains the integer weights of each of the n buckets, w1 . . . wn (1 ≤ w ≤
c).

Output
Output the minimum number of volunteers required to deliver all of the buckets of fish.

Sample Input 1 Sample Output 1


4 100 3
44 35 66 67

Sample Input 2 Sample Output 2


1 10 1
7

Sample Input 3 Sample Output 3


3 12 2
10 5 6
This page is intentionally left (almost) blank.
NCPC19G
Problem G
Game of Gnomes
Time limit: 1 second
The enemy and their massive army is approaching your
fortress, and all you have to defend it is a legion of
guardian gnomes. There is no hope of winning the
battle, so your focus will instead be on causing as
much damage as possible to the enemy.
You have n gnomes at your disposal. Before the
battle, they must be divided into at most m non-empty
groups. The battle will then proceed in turns. Each
turn, your gnomes will attack the enemy, causing one
unit of damage for each living gnome. Then the enemy
Picture by Danielle Walquist Lynch via flickr, cc by
will attack by throwing a lightning bolt at one of the
m groups. The lightning bolt kills k of the gnomes in that group, or all of them if the number of
living gnomes in the group is less than k. The battle ends when all gnomes are dead. The enemy
will always throw the lightning bolts in an optimal way such that the total damage caused by the
gnomes is minimized.
Now you wonder, what is the maximum amount of damage you can cause to the enemy if
you divide the gnomes into groups in an optimal way?
For example, if as in Sample Input 1 you have n = 10 gnomes that are to be divided into
m = 4 groups, and the lightning bolt does at most k = 3 damage, then an optimal solution
would be to create one large group of size 7 and three small groups of size 1. In the first round,
you cause 10 damage and the lightning bolt reduces the large group by 3. In the next round, you
cause 7 damage and the large group is reduced down to size 1. In the remaining four rounds you
do 4, 3, 2, and 1 damage respectively and the lightning bolt removes one group each round. In
total you do 10 + 7 + 4 + 3 + 2 + 1 = 27 damage.

Input
The input consists of a single line containing the three integers n, m, and k (1 ≤ n ≤ 109 ,
1 ≤ m, k ≤ 107 ), with meanings as described above.

Output
Output the maximum amount of damage you can cause to the enemy.

Sample Input 1 Sample Output 1


10 4 3 27

Sample Input 2 Sample Output 2


5 10 100 15

NCPC 2019 Problem G: Game of Gnomes 13


This page is intentionally left blank.
NCPC19H
Problem H
Hot Hike
Time limit: 2 seconds
In order to pass time during your vacation, you decided to go on a
hike to visit a scenic lake up in the mountains. Hiking to the lake
will take you a full day, then you will stay there for a day to rest and
enjoy the scenery, and then spend another day hiking home, for a
total of three days. However, the accursed weather this summer is
ridiculously warm and sunny, and since severe dehydration is not at
the top of your priority list you want to schedule the three-day trip
during some days where the two hiking days are the least warm. In
particular you want to minimize the maximum temperature during
Picture by dan lundmark on flickr, cc by
the two hiking days.
Given the current forecast of daily maximum temperatures during your vacation, what are
the best days for your trip?

Input
The first line of input contains an integer n (3 ≤ n ≤ 50), the length of your vacation in
days. Then follows a line containing n integers t1 , t2 , . . . , tn (−20 ≤ ti ≤ 40), where ti is the
temperature forecast for the i’th day of your vacation.

Output
Output two integers d and t, where d is the best day to start your trip, and t is the resulting
maximum temperature during the two hiking days. If there are many choices of d that minimize
the value of t, then output the smallest such d.

Sample Input 1 Sample Output 1


5 2 28
23 27 31 28 30

Sample Input 2 Sample Output 2


4 1 30
30 20 20 30

NCPC 2019 Problem H: Hot Hike 15


This page is intentionally left blank.
NCPC19I
Problem I
Incremental Induction
Time limit: 2 seconds
The Nordic Collegiate Pong Championship (NCPC) is an insanely
competive tournament where every contestant plays exactly one game
of Pong against every other contestant. The last game of the tourna-
ment just finished, so only one item now remains on the programme:
the traditional diploma ceremony, where all this year’s participants
get inducted into the NCPC Hall of Fame.
According to the ancient customs, contestants who have not been
inducted into the Hall of Fame yet (the pathetic nobodies) must stay on
the left side of the stage, whereas contestants who have been inducted Pong via Wikimedia Commons, public domain
(the awesome legends) must be on the right side of the stage. Then,
when a contestant is receiving their diploma, they will symbolically walk from the left to the
right side of the stage and thus become an awesome legend. Only one contestant is inducted
into the Hall of Fame at a time, and every contestant starts on the left side initially.
The NCPC Head of Jury believes it reflects badly on her if too many of the awesome legends
on the right have lost matches against pathetic nobodies on the left, but she quickly realizes
that it might be impossible to avoid this at every point in time during the diploma ceremony.
However, she certainly wants to keep such atrocities at a minimum. Specifically, she wants
to find the smallest number k for which there exists an order of handing out diplomas to the
contestants, such that at no point there were more than k games played where an awesome
legend lost against a pathetic nobody.

Input
The first line of input contains a single integer n (1 ≤ n ≤ 5 000), the number of contestants.
Then follows n − 1 lines, the ith of which contains a binary string of length i. The j th character on
the ith line is 1 if contestant i + 1 defeated contestant j, and 0 if contestant j defeated contestant
i + 1.

Output
Output a single integer k, the smallest number according to the requirements above.

Sample Input 1 Sample Output 1


4 1
1
01
100

Sample Input 2 Sample Output 2


5 3
0
00
100
1100

NCPC 2019 Problem I: Incremental Induction 17


This page is intentionally left blank.
Problem L UKIE19L
Low Effort League

The teams in your local rugby league aren’t particularly good, but they make up for it in
enthusiasm. We are going to organise a single-elimination knockout tournament between them,
where the 2n teams play n rounds. In each round, the 2i + 1th remaining team pairs up with the
2i + 2th team and one or the other team is eliminated.

Team1=1
Team1 +12

Team2=2

Team1 +22
Team3=3

Team3 +12
Team4=4

Team1 +42

Team5=8
Team6 +12

Team6=7
Team8 +22

Team7=6

Team8 +12
Team8=5

Each team has a scalar skill level. In the normal course of things, a team with higher skill level
will always beat a team with lower skill level. However, training plays a part too: if one team
studies another, learns its techniques, and trains against them, it can win.
The number of hours a team with skill a must train to beat a team with skill b (where a ≤ b) is
|b − a|2 . This training only affects that one game (it does not transfer to other teams).
You would quite like your favourite team to win the tournament. If you take complete control
over how every team trains, you can always make this happen. What is the minimum number of
hours needed, in total across all teams, in order for your team (team 1) to win?

Input
The input consists of:
• one line containing the integer r (1 ≤ r ≤ 14), the number of rounds in the tournament.
• one line with 2r integers s1 . . . s2 s (0 ≤ si ≤ 106 for each i), where si is the skill level of
the ith team.

Output
Output the smallest number of hours needed for team 1 to win the tournament.
Sample Input 1 Sample Output 1
1 0
50 40

Sample Input 2 Sample Output 2


3 28
1 2 3 4 8 7 6 5

You might also like