Untitled Document
Untitled Document
Shell game (USACO BRONZE): Calculate which shell was picked the most after simulating the
swaps and return that one as the answer
Mixing milk (USACO BRONZE): As the constraints are low, you can just simulate the pouring
action for every bucket and then output the answer
The Cow Signal (USACO BRONZE): Double the length of each row, then add that row below it
to double the column
Speeding ticket (USACO BRONZE): As it's from 1 → 100 miles, we can create a vector to store
Bessie’s speed in a given mile. Then we can loop through the array and compare the speed limit
at that mile with her speed at that mile, in turn we output the maximum positive difference.
(Essentially we are using vector simulation)
The lost cow (USACO BRONZE): The cow went 2 ** moves-1 steps each time. You can figure
out this pattern, then you can simulate the step taking and see if John has gone past her.
The bovine shuffle (USACO BRONZE): We are given the ending result and the shuffling order
for each turn. The ith element came from the position where I was. So find the position of the
element at position i + 1, and set the new array to have that cow at that position. (example: cow
5, find what position 5 is in the shuffling order, and then move cow 5 (or whatever cow was at
the 5th position) to that index)
The bucket list (USACO BRONZE): Every time a new cow started milking, you had to increase
the total amount of buckets needed, every time a cow stopped milking, you could decrease the
amount of buckets needed. If you stored the positions when the cows needed buckets and
didn’t need buckets, you could iterate through the array and pick out the time with maximum
buckets needed.
Measuring traffic (USACO BRONZE): You had to iterate going from left to right and then right to
left, making the correct equivalent sums and then returning the ans. (Bounds problem)
Circular barn (USACO BRONZE): As there are only 100 rooms, you could simulate how many
steps a cow would take in total and select the minimum out of all rooms. Btw for looping, you
can do count mod total rooms to get the index of the room you want.
Block game (USACO BRONZE): If you could figure out how many blocks you needed per 2
blocks (the maximum of each letter for each word), and then sum it up in total, you would get
the total amount of blocks needed for each card.
Team Tic Tac Toe (USACO BRONZE): You had to loop through each row of the grid via a
normal i, j loop with indexes [i][j], and then for each loop, store a set containing all the
different cows. If the set is equal to two, then you can add that pair to a (already won) pair and
not include it if it comes up again, same with one cow. For columns its i, j loop with [j][i]
indexes. For diagonals its a (top left to bottom right) [i][i] index, for top right to bottom
left its a reverse i loop with [n - 1 - i][i]
Mowing the field (USACO BRONZE): As all coordinates are relative, we can just assume we
start from 0,0 and then for each direction, store each possible coordinate he visits. If we match,
we take the most recent occurrence of that grid being cut and then subtract that from the current
time (as we store that position x,y was cut and index i which is the time). We then take the
smallest of these times as the answer
Censoring (USACO BRONZE): We could go through each letter of the array, add it to an answer
string, and for each letter added we could check if its longer than the substring we wanted and if
the ending of the substring of the ans string is equal to the substring, then we delete that part.
Naive string search algorithm with ‘string deletion’ also involved.
Milk measurement (USACO BRONZE): Keep an array that stores the current cows on display.
In addition, store the milk amounts for each cow from day I → 100. For each day, calculate the
highest value, then iterate to see which cows have the highest value and add them to the cows
on display array for that day. Finally, loop through the cows on display every day, if there is a
change (i.e. d-1 != d) then increment a counter. Finally, output the counter.
Stuck in a rut (USACO BRONZE): As the only way that cows can collide is by a north one going
up and an east one going right, we need to see how many times that happens. Essentially, we
can order the ones going north by their x values and east by their y values (the coordinate that
doesn’t change amongst all of them) and then start from the earliest to the latest one. If there is
a collision between two cows, then that must mean 1 of 2 things ) either cow A going east
stopped at the x coordinate of cow B or cow B going north stopped at the y coordinate of cow A.
Then for each cow, we can first check to see if that cow has not collided (i.e. their collision
location is -1) and if it is -1 we can go through that check and append the correct values to the
correct cow. Finally for both pairs, we can loop through all stopping points and calculate how far
they have gone and output that answer. If the answer is -1 then we output infinity. North = x, y +
1, East = x + 1, y
Maximum distance (USACO x CF): This is a brute force search, we can loop through every
possible pair with the following loop combo: i, j = i + 1. This ensures that there are never any
duplicates or double counted values. Then for each pair, apply the euclidean formula to the
pairs of numbers and store the maximum answer.
Milk pails (USACO BRONZE): For this one you had to simulate adding x 17’s (or whatever
number you are given) and y 25’s (whatever number you are given). You had to make sure that
the amount of 17s added was less than or equal to the target number. Finally, you store the
number closest to the target and output that.
Diamond collector (USACO BRONZE): Essentially, Bessie wants to display 2 diamonds in a
case. The two diamonds cannot have a value greater than k. So for each diamond, we can
assume it's the smaller one, (as if we assumed bigger or smaller, then the smaller diamond of
the two would consider the current diamond as bigger so the pair would’ve already been
counted), and for each diamond, we can sum up how many diamonds we can pair with diamond
x and the just output the maximum number we get.
Daisy chains (USACO BRONZE): Bessie takes an image of flowers from i, j (essentially all
possible combinations). In order to loop through all possible combinations (in terms of a range),
we use an i, j = i + 1 loop. Then the question asks us to see how many flowers have petals
equivalent to the average (mean) of the entire image taken. So for each possible combination,
we need to sum up all of the petals + the total items considered and then store that as the
average. Next we loop through all flowers from i → j (inclusive) and if they are equal to the avg.
flower, then we increment a counter. Finally we do counter + x (to also include ranges where i =
= j)
Bovine genomics (USACO BRONZE): First take in the input. In order to store the values we will
use a vvc for both the spotty cows and the plains. This will contain the values of all cows at a
given segment. If any of the cows at that segment have a gene that matches with plain, then it
can’t be a possible segment, otherwise increment counter.s