Time Limit: 1 second
Justin and Donald are playing their favourite game: hop chess. You probably haven’t heard of it, but the rules are pretty simple.
The board is a rectangular grid, with each square of the board
initially having exactly one player’s piece on it. Justin’s pieces are
denoted as J
, with Donald’s being
D
. Each player has at least one piece on the
grid initially.
The game begins with Justin playing first. On a turn, a player may
move one of his pieces to capture (and thus remove from the board) a
neighbouring piece (not necessarily the opponent’s). A piece
In an ideal world, both Justin and Donald are perfect logicians, and
capable of discerning an optimal strategy for any board. Then perhaps we
might be interested in who of the two would win. But that wouldn’t be
very realistic. Indeed, when playing, Justin and Donald can both come up
with a relatively good solution; exactly how good it tends to be is
determined by their error factors,
Formally, the active player with error factor
Both players, when given the choice of choosing their proposal set, chooses the most optimal such set (one which produces the highest probability of winning), knowing that the other player always chooses their proposal set optimally as well.
The natural question is then: exactly what is the probability that
Justin wins a game of hop chess, given the initial board,
Input will begin with two space-separated positive integers J, D
},
describing the initial board state. Finally, there will be two
space-separated integers,
Output a single floating point number rounded to 3 decimal places: the probability that Justin wins.
1 3
JJD
3 1
0.667
Note that Justin has 3 possible moves (note that
_
indicates an empty cell in all explanations
below):
he moves his first piece right, capturing his second piece, and
ensuring his loss by having the board appear as
_JD
;
he moves his second piece right, capturing Donald’s piece and
securing victory, with the board as
J_J
;
or he moves his second piece left, capturing his own piece, but
leaving Donald unable to move, thus also winning, with the board as
J_D
.
Clearly the latter 2 cases are optimal—but since Justin has error factor 3, there is a 1/3 chance that he chooses the option causing him to lose. Thus he wins with probability 2/3.
2 2
JJ
DD
3 1
0.000
There is no hope for Justin to win.
To see why, notice that Justin has 4 possible first moves:
|
|
|
|
He can pick any subset of size three from the above moves.
However, Donald will always pick his most optimal move. Regardless of Justin’s first move, Donald will leave the board in one of the following configurations:
|
|
|
|
all of which will cause Justin to lose.
Time Limit: 2 seconds
In a fancy new zero-person video game, Sirtet, the game is a
rectangular grid with .
) and
others are filled (denoted as #
). The filled
squares represent a set of objects, and the filled squares that are
adjacent (horizontally or vertically) should be considered to be part of
the same rigid object. For example, this initial grid:
..#.
##.#
.##.
#...
#...
has four objects, shown below:
|
|
|
|
When the game begins, the objects fall straight down the grid, all at the same speed. Each object continues to fall straight down until it either touches the bottom row, or has some part of it land directly on top of another object, at which point it stops. What will be the final state of the grid?
The first line contains two space-separated positive integers
The following #
, otherwise it will be a
.
character.
For 10 of the 25 available marks,
For an additional 6 of the 25 available marks,
Output #
, otherwise it will be a
.
character.
5 4
..#.
##.#
.##.
#...
#...
....
....
###.
###.
#..#
Time Limit: 1 second
In the Great White North, there are
During winter, all roads will be converted into one-way highways due
to dangerous driving conditions. That is, road
Every citizen wants to send a holiday card to every other citizen.
Citizen
What is the maximum number of holiday cards that can be sent after converting all roads to highways?
The first line contains one integer
The second line contains
The third line contains
Let
For
For an additional
For an additional
For an additional
Print one line with one integer, the maximum number of cards that can be sent after converting all roads to highways.
4
3 3 4 1
1 2 1
67
One possible way of converting roads to highways is for road
Consider the following pictures, with the cities and associated population (in parentheses) for the initial roads
and what it looks like after all roads are converted to highways:
Every citizen in city 3 can send 3 holiday cards to city 3 citizens, 3 holiday cards to city 2 citizens, 3 holiday cards to city 1 citizens, and 1 holiday card to the city 4 citizen, for a total of 40 holiday cards sent out of city 3.
Similarly,
city 2 citizens send 6 holidays cards each, for a total of 18 holiday cards.
city 1 citizens send 3 holidays cards each, for a total of 9 holiday cards.
the city 4 citizen cannot send any holiday cards.
A total of
Time Limit: 6 seconds
You have a deck of
You are playing a game that involves drawing all the cards from the
deck one by one. When you draw a card, you may choose to either add it
to your hand or discard it. You may also score
your entire hand at any time. When you score a hand with
The first line of input will contain two space-separated integers
For 4 of the 25 marks available,
For an additional 1 of the 25 marks available,
For an additional 5 of the 25 marks available,
For an additional 3 of the 25 marks available,
For an additional 3 of the 25 marks available,
Output one floating point number, which is the maximum score you can obtain from playing optimally.
If your answer is
3 5
1
2
2
1
1
6.656854249
We know the cards we draw in order are
The optimal strategy is to draw one card, score that hand, draw two
cards, score that hand, and draw two more cards and score that hand.
This strategy gives a score of
4 5
1
2
2
1
1
9.0
We know the cards we draw in order are
An optimal strategy is to take all cards with
Time Limit: 4 seconds
Hannah is building a structure made of marshmallows and skewers for
her chemistry class. The structure will contain
Hannah has
To ensure the stability of the structure, the following requirement
must also be satisfied: if
Due to austerity measures imposed by the principal’s office, skewers are scarce in Hannah’s school. Find the minimum number of skewers necessary to satisfy all requirements.
The first line contains two space-separated integers
The next
For 5 of the 25 marks available,
For an additional 5 of the 25 marks available,
For an additional 5 of the 25 marks available, for all
Output a single integer, the minimum total number of skewers.
6 4
1 2
1 4
4 6
4 5
6
In addition to those already required, there must be skewers between
the pairs of marshmallows
7 6
2 3
2 6
2 7
1 3
1 4
1 5
16
Time Limit: 1 second
Your friend has constructed a code that they want to use to send
secret messages to you. The messages will only be composed of
However, you are not sure the code is going to work: there is a chance that a binary sequence can correspond to two (or more) different messages.
For example, if the code was:
Your job is determine the length of the shortest binary sequence that corresponds to two different messages, or determine that there are no binary sequences which correspond to two different messages.
The first line of input will contain two space-separated integers
For 4 of the 25 marks available,
For an additional 7 of the 25 marks available, each of the binary
sequences contains exactly one 1
bit. For
example, the sequences 00100
or
1000
would be valid in this case.
Output will be one line long.
If there is a binary sequence that corresponds to two (or more)
messages, print the length of the shortest such binary sequence;
otherwise, output one line containing -1
.
4 3
101
10
1
100
3
This is the sample in the problem description.
4 4
1011
1000
1111
1001
-1
There is no binary sequence that corresponds to more than one
message. Notice that since each code is 4 bits, and none are the same,
every encoding of