Free For All 7 Sam Loyd's Puzzle Carnival II
Free For All 7 Sam Loyd's Puzzle Carnival II
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case starts with two integers in a single line: N and S. The second line for each test case contains N
integers in ascending order: P1 , P2 , . . . , PN .
T 6 500 ; 1 6 N 6 50 ; 1 6 P1 < P2 < P3 < . . . < PN 6 S 6 300
Output
For each test case, print the case number, followed by the minimum number of arrows required to score S
points between square brackets, and then the sequence of points for each arrow, in descending order. These
scores must be separated by single spaces.
If the test case does not have a solution, simply print the case number, followed by the string impossible.
Sample Input
Case 1: [6] 17 17 17 17 16 16
6 100
Case 2: [3] 20 20 10
16 17 23 24 39 40
Case 3: impossible
3 50
10 15 20
2 25
7 13
Input
Input starts with a positive integer T , that denotes the number of test cases.
Theres a blank line at the beginning of each case. Then two integers are given in a single line: N and M,
representing the number of nodes and the number of bi-directional edges in the graph, respectively. You can
assume that there is at most one edge between any pair of nodes, and that each edge will be reported only
once.
The next line will contain N distinct letters, separated by spaces, which are the identifiers for all the nodes
in the graph. The first letter in this list will be the source, the last letter will be the target. All letters will be
uppercase letters from the English alphabet.
Then M lines will be presented, describing the edges of the graph. Each of these lines contain two distinct
letters, which describe two nodes that are connected by an edge.
T 6 60 ; 2 6 N 6 15
Output
For each test case, print the case number, followed by the sequence of letters that describe the path from the
source to the target, visiting all nodes exactly once.
If a valid solution doesnt exist, print the word impossible.
Sample Input
Case 1: AVCDYFUBWXEZ
Case 2: impossible
12 14
Case 3: LINK
A B C D E F U V W X Y Z
A F
A V
B U
B W
C D
C V
D Y
D W
E X
E Z
F U
F Y
U Z
W X
3 2
A B C
A B
A C
4 5
L N I K
L N
I L
I N
K N
K I
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case is described by a single integer L, in its own line.
T 6 3000 ; 1 6 L 6 105
Output
For each test case, print the case number, followed by the total distance covered by the courier. Print this
result as a real number, with exactly two digits after the decimal point.
Sample Input
Case 1: 120.71
50
Your task now is to identify all possible triangles (right-angled and with sides of integer lengths, as in the
puzzle) with a certain area A. Print the lengths of each triangle in ascending order, and the whole list of
triangles in ascending order as wellsort the triangles first by their first (shortest) side, then the second side
and finally by their longest side.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test is described by a single integer A, in a line of its own.
T 6 104 ; 1 6 A 6 107
Output
For each test case, print the case number, followed by the number of valid triangles with area A. Then print
the sorted list of these triangles, one per line, using the format (a,b,c), where a, b, c are the lengths of the
sides of the triangle, in ascending order.
Sample Input
Case 1: 2
210
(12,35,37)
1000
(20,21,29)
2400
Case 2: 0
3360
Case 3: 1
(60,80,100)
Case 4: 3
(30,224,226)
(48,140,148)
(80,84,116)
Given a list of 10 integers, representing the weighs of each couple formed from a group of 5 people, determine
the weights of each person.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case is described by 10 integers W1 , W2 , . . . , W10 in a single line.
T 6 3000 ; 100 6 W1 6 W2 6 . . . 6 W10 6 400
Output
For each test case, print the case number, followed by the 5 weights asked, separated by spaces. Print these
numbers in ascending order.
Sample Input
Case 1: 56 58 60 64 65
114 116 118 120 121 122 123 124 125 129
Case 2: 53 57 58 61 65
110 111 114 115 118 118 119 122 123 126
180 190 190 196 196 206 216 216 226 232
You receive the description of several grids, each one with ten coins placed on it arbitrarily. Solve the Jolly
Friars puzzle for each grid.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case begins with a blank line, followed by four lines with four characters each, describing a grid.
Each character of the grid is either a dot (.) or an asterisk (*) which denote an empty cell or a coin, respectively.
Every grid will have exactly ten coins.
T 6 1000
Output
For each test case, print the case number, followed by the minimum number of moves required to make the
grid optimal.
Sample Input
Case 1: 4
Case 2: 1
****
*.*.
.**.
*..*
*.*.
.***
*.**
.**.
Which has 16 even lines. For the second case, just one move is necessary to turn it into an optimal grid (the
question of which move is left as an exercise).
Analyzing the game, it is not very complicated to figure out a winning strategy for the second player, as
long as the game starts with a complete flower (having all of its petals intact). However, what will happen
when Gretchen plays against an opponent that also plays optimally, and some of the flowers petals have been
plucked off at random?
A flower is described by a number N which represents the original number of petals of the flower, and a list of
the petals that have been plucked off. All petals are numbered from 1 to N, and given the circular nature of
the flower, that means petals 1 and N are originally adjacent.
Given the description of a flower, and assuming its Gretchens turn, will she win the game? Remember that
both players always play optimally.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case begins with two integers in a single line, N and M, representing the number of petals originally
in the flower, and the number of petals that have been plucked off, respectively.
The next line contains M distinct integers, representing the petals that have been plucked off. These numbers
will always be in ascending order.
T 6 5000 ; 3 6 N 6 20 ; 1 6 M < N
Output
For each test case, print the case number, followed by the string yes if Gretchen wins the game, or no otherwise.
Sample Input
Case 1: yes
13 1
Case 2: no
7
5 3
1 3 4
10
You receive a description of a board, where a number of pieces (between 1 and 9) are arbitrarily scattered
throughout the board. Your task is to determine the minimum number of moves required to win the game
with any of its pieces.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each case starts with a blank line. The next five lines contain five characters each, and they describe the
board. Each character of the board will be either a dot (.) or an asterisk (*). Dots represent empty squares,
and asterisks represent game pieces. The number of pieces will be always between 1 and 9 (inclusive).
T 6 100
Output
For each test case, print the case number, followed by the minimum number of moves required to capture all
pieces on the board except for one, leaving the winner on the center of the board.
11
Sample Input
Case 1: 8
Case 2: 2
.....
Case 3: 5
.***.
.***.
.***.
.....
.....
.*...
..*..
.....
.....
.....
..*..
.***.
..*..
.....
2 jumps 6.
5 jumps 8.
2 jumps 9.
7 jumps 2.
5 jumps 7.
5 jumps 3.
5 jumps 1.
5 jumps 4.
For the second case, the topmost piece jumps over the other, and then moves back into the center, for a total
of 2 moves.
For the third case, there is an interesting way to solve it in 5 moves, which is left as an exercise.
12
Every hour the tower clock sounds a large bell as many times as the
number of hours it is marking. So, for example, at 6 oclock it sounds
the bell six times. The time it takes to complete this task is counted
from the moment it hits the bell the first time until the moment it
hits it the last time. The time between consecutive strikes is always
constant.
You know that at hour H1 it takes the clock exactly S seconds to strike H1 . How long would it take to strike a
different hour H2 ?
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case is described by three integer numbers in a single line, in order: H1 , S, H2 .
T 6 5000 ; 2 6 H1 , H2 6 12 ; 0 < S < 60 ; H1 6= H2
Output
For each test case, print the case number, followed by the exact number of seconds that the clock takes to
mark H2 .
If this number is not an integer, and is less than 1, then print it as a simplified fraction p/q (that is, p and q
have to be coprimes).
If the answer is not an integer, and is greater than 1, then print it as a mixed number, with its fraction part
simplified. See the samples below for the formatting details.
Sample Input
Case 1: 13 1/5
6 6 12
Case 2: 12
6 6 11
Case 3: 1/2
3 1 2
13
As you can see, there are three types of jars, which we will call small,
medium and large. Mrs. Hubbard puts a certain number of jars on each
of her three shelves. If all jars are completely filled with jam, and you
know the total amount of jam in each shelf, determine the capacity of
each type of jar.
Mrs. Hubbards kids inspect the jam
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case begins with a blank line; after that, there will be three lines describing each shelf.
A shelf is described by four numbers, in order: three integers S, M, L which represent the number of small,
medium and large jars in the shelf, and a real number J that represents the total amount of jam for that shelf.
The value of J will always be presented with two digits after the decimal point. You may assume that all test
cases have a valid answer.
T 6 5000 ; 0 6 S, M, L 6 15 ; 0 < J 6 100
Output
For each test case, print the case number, followed by the capacity of the small, medium and large jars, in that
order. Print the answers as real numbers rounded to exactly two digits after the decimal point.
Sample Input
3 3 1 20.00
6 0 2 20.00
6 4 0 20.00
3 0 1 6.00
0 2 2 10.00
1 3 1 10.00
14
Assume that the race always happens in a track one mile long, and that the skaters always maintain constant
speeds. Let vJ be Jennies speed, and vM Maudes speed. We will call r the ratio between the two speedsthat
is, r = vJ vM . Let t be the time in minutes between the moment when Jennie finished the race and the
moment when Maude did the same. Given the values r and t, determine the time that each skater took to
complete the race.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case contains two real numbers: r and t, as described above. Each number will be presented with
two digits after the decimal point.
T 6 5000 ; 1 < r 6 10 ; 0 < t 6 30
Output
For each test case, print the case number, followed by two real numbers: the time in minutes of Jennie and
Maude to complete the race, in that order. Print these numbers with exactly three digits after the decimal
point.
Sample Input
2.50 6.00
1.88 3.33
15
Can you indicate the diameter of the required lid to fit on the
kettle, which is twelve inches deep, and will hold just twenty-five
gallons?
Given the depth of the kettle, and the volume it can hold, calculate its diameter at the topwhich is twice the
diameter at the bottom. The depth is given in inches, while the volume is given in beer gallons, which you
should assume to be equivalent to 282 cubic inches.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case contains two integers: D and V which denote the depth and the volume of the kettle, respectively.
T 6 1000 ; 1 6 D 6 50 ; 1 6 V 6 100
Output
For each test case, print the case number, followed by the diameter at the top of the kettle, in inches. Print this
as a real number rounded to exactly three digits after the decimal point.
Sample Input
Case 1: 35.810
12 25
Case 2: 45.069
10 33
16
Lets say that the miser was able to divide his gold in N different ways, and
for each method of partitioning he was able to form Mi similar groups (for
1 6 i 6 N). You are asked now to determine the minimum amount of gold
he had.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each case starts with an integer N in a single line. The next line contains N integers, representing the set
M1 , M2 , . . . , MN .
T 6 2000 ; 1 6 N 6 8 ; 2 6 M1 < M2 < M3 < . . . < MN 6 100
Output
For each test case, print the case number, followed by the the minimum amount of gold that the miser could
have.
Sample Input
Case 1: 2100
Case 2: 7350
4 5 6
4
10 14 15 35
17
Assume that the tracks marked on the floor are perfectly circular, that the distance between a wheel on one
side and its opposite on the other side is D feet, and that for one turn of the inner wheels, the outer wheels
make N turns. Determine the circumference of the circle formed by the outer wheels.
Input
Input starts with a positive integer T , that denotes the number of test cases.
Each test case is described by the two real numbers D and N in the same line. These numbers are always
given with two digits after the decimal point.
T 6 1000 ; 3 6 D 6 10 ; 1 < N 6 10
Output
For each test case, print the case number, followed by the circumference of the outer tracks (in feet), with
exactly three digits after the decimal point.
Sample Input
Case 1: 62.832
5.00 2.00
Case 2: 86.365
4.20 1.44
Case 3: 100.408
8.03 2.01
18