Usaco Jan12 Silver

Part of USACO Jan12

```
**********************************************************************
SILVER PROBLEMS
**********************************************************************
Three problems numbered 1 through 3
**********************************************************************
Problem 1: Delivery Route [Brian Dean, 2012]
After several years of record milk production, Farmer John now operates an
entire network of N farms (1 <= N <= 100). Farm i is located at position
(x_i, y_i) in the 2D plane, distinct from all other farms, with both x_i
and y_i being integers.
FJ needs your help planning his daily delivery route to bring supplies to
the N farms. Starting from farm 1, he plans to visit the farms
sequentially (farm 1, then farm 2, then farm 3, etc.), finally returning to
farm 1 after visiting farm N. It tames FJ one minute to make a single step
either north, south, east, or west. Furthermore, FJ wants to visit each
farm exactly once during his entire journey (except farm 1, which he visits
twice of course).
Please help FJ determine the minimum amount of time it will take him to
complete his entire delivery route.
PROBLEM NAME: delivery
INPUT FORMAT:
* Line 1: The number of farms, N.
* Lines 2..1+N: Line i+1 contains two space-separated integers, x_i
and y_i (1 <= x_i, y_i <= 1,000,000).
SAMPLE INPUT (file delivery.in):
4
2 2
2 4
2 1
1 3
OUTPUT FORMAT:
* Line 1: The minimum number of minutes FJ needs to complete his
delivery route, or -1 if it is impossible to find a feasible
delivery route that visits every farm exactly once (except
farm 1).
SAMPLE OUTPUT (file delivery.out):
12
OUTPUT DETAILS:
FJ can complete his delivery route in 12 minutes: 2 minutes to go from farm
1 to farm 2, 5 minutes to go from farm 2 to farm 3 (circumventing farm 1),
3 minutes to go from farm 3 to farm 4, and then 2 minutes to return to farm 1.
**********************************************************************
Problem 2: Bale Share [Fatih Gelgi, 2010]
Farmer John has just received a new shipment of N (1 <= N <= 20) bales of
hay, where bale i has size S_i (1 <= S_i <= 100). He wants to divide the
bales between his three barns as fairly as possible.
After some careful thought, FJ decides that a "fair" division of the hay
bales should make the largest share as small as possible. That is, if B_1,
B_2, and B_3 are the total sizes of all the bales placed in barns 1, 2, and
3, respectively (where B_1 >= B_2 >= B_3), then FJ wants to make B_1 as
small as possible.
For example, if there are 8 bales in these sizes:
2 4 5 8 9 14 15 20
A fair solution is
Barn 1: 2 9 15 B_1 = 26
Barn 2: 4 8 14 B_2 = 26
Barn 3: 5 20 B_3 = 25
Please help FJ determine the value of B_1 for a fair division of the hay bales.
PROBLEM NAME: baleshare
INPUT FORMAT:
* Line 1: The number of bales, N.
* Lines 2..1+N: Line i+1 contains S_i, the size of the ith bale.
SAMPLE INPUT (file baleshare.in):
8
14
2
5
15
8
9
20
4
OUTPUT FORMAT:
* Line 1: Please output the value of B_1 in a fair division of the hay
bales.
SAMPLE OUTPUT (file baleshare.out):
26
**********************************************************************
Problem 3: Mountain Climbing [Videh Seksaria, 2012]
Farmer John has discovered that his cows produce higher quality milk when
they are subject to strenuous exercise. He therefore decides to send his N
cows (1 <= N <= 25,000) to climb up and then back down a nearby mountain!
Cow i takes U(i) time to climb up the mountain and then D(i) time to climb
down the mountain. Being domesticated cows, each cow needs the help of a
farmer for each leg of the climb, but due to the poor economy, there are
only two farmers available, Farmer John and his cousin Farmer Don. FJ
plans to guide cows for the upward climb, and FD will then guide the cows
for the downward climb. Since every cow needs a guide, and there is only
one farmer for each part of the voyage, at most one cow may be climbing
upward at any point in time (assisted by FJ), and at most one cow may be
climbing down at any point in time (assisted by FD). A group of cows may
temporarily accumulate at the top of the mountain if they climb up and then
need to wait for FD's assistance before climbing down. Cows may climb down
in a different order than they climbed up.
Please determine the least possible amount of time for all N cows to make
the entire journey.
PROBLEM NAME: climb
INPUT FORMAT:
* Line 1: The number of cows, N.
* Lines 2..1+N: Line i+1 contains two space-separated integers: U(i)
and D(i). (1 <= U(i), D(i) <= 50,000).
SAMPLE INPUT (file climb.in):
3
6 4
8 1
2 3
OUTPUT FORMAT:
* Line 1: A single integer representing the least amount of time for
all the cows to cross the mountain.
SAMPLE OUTPUT (file climb.out):
17
OUTPUT DETAILS:
If cow 3 goes first, then cow 1, and then cow 2 (and this same order is
used for both the ascent and descent), this gives a total time of 17.
**********************************************************************
```

page revision: 0, last edited: 14 Jan 2012 15:19