Problem C: Cocoa Coalition
Problem C: Cocoa Coalition
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.
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 .
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 .
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.
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.
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.
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.
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