Sei sulla pagina 1di 7

2019 Mock USACO Contest, Bronze

mathchampion1
January 2019

0 Introduction
The standard rules as a USACO apply - three problems with four hours to solve
them. However, this will not be scored formally; instead, the correctness of your
code will be checked. For each problem you can do completely correctly, you
will earn 1 point, for a maximum of 3 and a minimum of 0.

1
2019 Mock USACO Contest, Bronze
Problem 1. String Game

Cows Bessie and Mildred are tired of their seemingly endless commitment to
their farm. After a few agreements and disagreements, they come up with a
game they will play together to entertain themselves in their free time.

First, Bessie will say an integer N (0 < N ≤ 1000).

Second, Mildred will say a string s1 of length N . It is guaranteed that s1


will only consist of lowercase letters.

Then, Bessie will remove all of the letters with odd index in s1 (where indexing
starts at 0 and ends at N − 1), and then say this new modified version of s1 ,
which we will call s2 . For example, if s1 is the string “abcdefg,” (in which case
N = 7) then Bessie will remove the letters ‘b’ (with index 1), ‘d’ (with index
3), and ‘f’ (with index 5). The resultant string s2 will be “aceg.”

Next, Mildred will remove all letters with odd index in s2 to form a new string
s3 , which she says out loud (in our example, this would be “ae”).

The cows continue alternating to remove letters with odd indices from the last
said string, and this continues all the way until one of the two cows first says
a string with exactly one letter (meaning that it has length 1), at which point
the game ends, and the cow that said the one-letter string wins.

Given N and s1 , please determine the cow that wins the corresponding game,
along with the final one-letter string that is said.

INPUT FORMAT (file game.in):

The first line of input contains N .

The second line of input contains s1 .

OUTPUT FORMAT (file game.out):

On the first line, please output the name of the cow that wins the game that
corresponds to the given values of N and s1 .

On the second line, please output the final one-letter string that is said in
this game.

2
SAMPLE INPUT:

7
abcdefg

SAMPLE OUTPUT:

Bessie
a

Following the game through, it is clear that Bessie is the cow that says the
final one-letter string, which ends up being “a.”

Problem credits: mathchampion1

3
2019 Mock USACO Contest, Bronze
Problem 2. Cow-Goes-Moo

Cows Bessie and Mildred from the previous problem are bored of playing their
string game, and are looking for something more challenging and less pre-
dictable.

Luckily, Farmer John, a farmer they have known for all their lives, is will-
ing to help them. He suggests them to try playing Tic-Tac-Toe, a common
human game, but Bessie and Mildred want to create their own spin-off, called
“Cow-Goes-Moo,” and the game procedure can be laid out as follows.

First, Farmer John draws out a 3×3 grid of squares (effectively resulting in nine
cells) on the ground. He randomly chooses some of these squares and places
exactly one hay bale in each of the chosen squares (he may also choose to place
hay bales in none of the squares).

Then, Bessie and Mildred will each take turns placing hay bales in the vacant
squares until one of the two cows first gets three hay bales in a row (Farmer
John’s initial hay bales are included in this count). It is up to the two of them
to decide who places the first hay bale.

In the case of Cow-Goes-Moo, Bessie and Mildred only count three hay bales
as being “in a row” if all three hay bales are exactly lined up in a horizontal
row of the 3×3 grid (meaning that columns, diagonals, and so on do not count).

Another caveat is that the cow that first obtains three hay bales in a row is
declared the loser (not the winner, unlike Tic-Tac-Toe), meaning that the other
cow is automatically declared the winner.

Given Farmer John’s initial 3×3 Cow-Goes-Moo setup, and the name of the cow
that places the first hay bale, please determine the winner of the corresponding
Cow-Goes-Moo game, along with the number of moves it takes to determine
the winner. Assume that Bessie and Mildred each play with their best possible
strategies.

4
INPUT FORMAT (file cowgoesmoo.in):

The first line of input contains the first row of Farmer John’s initial board,
the second line contains the second row, and the third line contains the third
row. Each of the three cells in a given row are coded so that a 0 means that
there is no hay bale present in a certain cell initially, and a 1 means that there
is a hay bale present in a certain cell initially. Furthermore, for each row, the
three values denoting the three cells are space-separated.

The fourth line contains the name of the cow that places the first hay bale.

OUTPUT FORMAT (file cowgoesmoo.out):

On the first line, please output the name of the cow that wins the corresponding
Cow-Goes-Moo game.

On the second line, please output the number of moves it takes to declare the
winner.

SAMPLE INPUT:

100
001
010
Mildred

SAMPLE OUTPUT:

Mildred
4

In this example, Mildred goes first and places a hay bale in one of the va-
cant cells in the first row. Then, Bessie goes second and places a hay bale in one
of the vacant cells in the second row. Next, Mildred places a hay bale in one of
the vacant cells in the third row. Now, no matter what, Bessie is forced to place
a hay bale in a row where the other two cells already have hay bales in them,
meaning that she is forced to get three hay bales in a row and lose. The desig-
nated winner is then Mildred, and it took a total of four moves to determine this.

Problem credits: mathchampion1

5
2019 Mock USACO Contest, Bronze
Problem 3. Cow Lineup

Farmer John has 52 cows. Exhausted because of the hard labor of his farm,
he is unable to find names for them, but still thinks they deserve names for
providing him with the milk that helps run his farm.

After much thought on what to do, he decides to name each of them after
an uppercase or lowercase letter of the alphabet. In particular, he names his
cows with the letters a . . . z, and the letters A . . . Z.

One day, after he wins the annual Best Farm award, he decides to take a picture
of himself to celebrate the occasion. Being the generous man he is, he decides
to let NP (0 < NP ≤ 52) of his 52 cows be in the picture with him, all lined up
right behind him.

He wants the NP cows to line up so that a cow named a certain lowercase


letter is always to the left of the cow named the corresponding uppercase letter,
so that cow a is to the left of cow A, and cow b is to the left of cow B.

Furthermore, he wants the cows to be in alphabetical order in their respec-


tive case (uppercase or lowercase) from left to right, meaning that cow a must
be to the left of b, cow A must be to the left of cow B, cow b must be to the
left of cow c, cow B must be to the left of cow C, and so on.

Note that “to the left of” does not require a certain cow to be immediately
to the left of (adjacent to) another cow, but just somewhere to the left of the
other cow. For example, a A b B is a valid arrangement.

Given these requirements, please help Farmer John determine the number of
distinct ways he can arrange his NP cows behind him in a line.

INPUT FORMAT (file lineup.in):

The first line of input contains NP.

The second line contains NP space-separated letters, some of which are up-
percase, and some of which are lowercase (in no particular order, and it is not
guaranteed that at least one of these letters are uppercase or at least one of these
letters is lowercase), specifying the exact cows Farmer John wants to include in
the picture.

6
OUTPUT FORMAT (file lineup.out):

Please output one integer, specifying the number of ways that Farmer John
can arrange his NP chosen cows in a line, based on his requirements.

SAMPLE INPUT:

4
BabA

SAMPLE OUTPUT:

In this example, the only two permissible arrangements are a b A B and a A b B.


All other arrangements do not meet Farmer John’s requirements.

Problem credits: mathchampion1

Potrebbero piacerti anche