Usaco Jan12 Bronze
Part of USACO Jan12
**********************************************************************
BRONZE PROBLEMS
**********************************************************************
Three problems numbered 1 through 3
**********************************************************************
Problem 1: Gifts [Kalki Seksaria and Brian Dean, 2012]
Farmer John wants to give gifts to his N (1 <= N <= 1000) cows, using his
total budget of B (1 <= B <= 1,000,000,000) units of money.
Cow i requests a gift with a price of P(i) units, and a shipping cost of
S(i) units (so the total cost would be P(i)+S(i) for FJ to order this
gift). FJ has a special coupon that he can use to order one gift of his
choosing at only half its normal price. If FJ uses the coupon for cow i,
he therefore would only need to pay P(i)/2+S(i) for that cow's gift.
Conveniently, the P(i)'s are all even numbers.
Please help FJ determine the maximum number of cows to whom he can afford
to give gifts.
PROBLEM NAME: gifts
INPUT FORMAT:
* Line 1: Two spaceseparated integers, N and B.
* Lines 2..1+N: Line i+1 contains two spaceseparated integers, P(i)
and S(i). (0 <= P(i),S(i) <= 1,000,000,000, with P(i) even)
SAMPLE INPUT (file gifts.in):
5 24
4 2
2 0
8 1
6 3
12 5
INPUT DETAILS:
There are 5 cows, and FJ has a budget of 24. Cow 1 desires a gift with
price 4 and shipping cost 2, etc.
OUTPUT FORMAT:
* Line 1: The maximum number of cows for whom FJ can purchase gifts.
SAMPLE OUTPUT (file gifts.out):
4
OUTPUT DETAILS:
FJ can purchase gifts for cows 1 through 4, if he uses the coupon for cow
3. His total cost is (4+2)+(2+0)+(4+1)+(6+3) = 22. Note that FJ could
have used the coupon instead on cow 1 or 4 and still met his budget.
**********************************************************************
Problem 2: Haybale Stacking [Brian Dean, 2012]
Feeling sorry for all the mischief she has caused around the farm recently,
Bessie has agreed to help Farmer John stack up an incoming shipment of hay
bales.
She starts with N (1 <= N <= 1,000,000, N odd) empty stacks, numbered 1..N.
FJ then gives her a sequence of K instructions (1 <= K <= 25,000), each of
the form "A B", meaning that Bessie should add one new haybale to the top
of each stack in the range A..B. For example, if Bessie is told "10 13",
then she should add a haybale to each of the stacks 10, 11, 12, and 13.
After Bessie finishes stacking haybales according to his instructions, FJ
would like to know the median height of his N stacks  that is, the height
of the middle stack if the stacks were to be arranged in sorted order
(conveniently, N is odd, so this stack is unique). Please help Bessie
determine the answer to FJ's question.
PROBLEM NAME: stacking
INPUT FORMAT:
* Line 1: Two spaceseparated integers, N K.
* Lines 2..1+K: Each line contains one of FJ's instructions in the
form of two spaceseparated integers A B (1 <= A <= B <= N).
SAMPLE INPUT (file stacking.in):
7 4
5 5
2 4
4 6
3 5
INPUT DETAILS:
There are N=7 stacks, and FJ issues K=4 instructions. The first
instruction is to add a haybale to stack 5, the second is to add haybales
to stacks 2..4, etc.
OUTPUT FORMAT:
* Line 1: The median height of a stack after Bessie completes the
instructions.
SAMPLE OUTPUT (file stacking.out):
1
OUTPUT DETAILS:
After Bessie is finished, the stacks have heights 0,1,2,3,3,1,0. The median
stack height is 1, since 1 is the middle element in the sorted ordering
0,0,1,1,2,3,3.
**********************************************************************
Problem 3: Grazing Patterns [Brian Dean, 2012]
Due to recent budget cuts, FJ has downsized his farm so that the grazing
area for his cows is only a 5 meter by 5 meter square field! The field is
laid out like a 5x5 grid of 1 meter by 1 meter squares, with (1,1) being
the location of the upperleft square, and (5,5) being the location of the
lowerright square:
(1,1) (1,2) (1,3) (1,4) (1,5)
(2,1) (2,2) (2,3) (2,4) (2,5)
(3,1) (3,2) (3,3) (3,4) (3,5)
(4,1) (4,2) (4,3) (4,4) (4,5)
(5,1) (5,2) (5,3) (5,4) (5,5)
Every square in this grid is filled with delicious grass, except for K
barren squares (0 <= K <= 22, K even), which have no grass. Bessie the cow
starts grazing in square (1,1), which is always filled with grass, and
Mildred the cow starts grazing in square (5,5), which also is always filled
with grass.
Each halfhour, Bessie and Mildred finish eating all the grass in their
respective squares and each both move to adjacent grassy squares (north,
south, east, or west). They want to consume all the grassy squares and end
up in exactly the same final location. Please compute the number of
different ways this can happen. Bessie and Mildred always move onto
grassy squares, and they never both move onto the same square unless that
is the very last grassy square remaining.
PROBLEM NAME: grazing
INPUT FORMAT:
* Line 1: The integer K.
* Lines 2..1+K: Each line contains the location (i,j) of a nongrassy
square by listing the two spaceseparated integers i and j.
SAMPLE INPUT (file grazing.in):
4
3 2
3 3
3 4
3 1
INPUT DETAILS:
The initial grid looks like this (where . denotes a grassy square, x
denotes a nongrassy square, b indicates the starting location of Bessie,
and m indicates the starting location of Mildred):
b . . . .
. . . . .
x x x x .
. . . . .
. . . . m
OUTPUT FORMAT:
* Line 1: The number of different possible ways Bessie and Mildred can
walk across the field to eat all the grass and end up in the
same final location.
SAMPLE OUTPUT (file grazing.out):
1
OUTPUT DETAILS:
There is only one possible solution, with Bessie and Mildred meeting at
square (3,5):
b bb bb
    
bb bb b

x x x x b/m

mmmmm

mmmmm
**********************************************************************
page revision: 0, last edited: 14 Jan 2012 15:20