Problem 1
Easy Problem
It doesn't get any easier than this: you will be given a triangle with integer coordinates and must
return the midpoint of the longest side. Moreover, the answer will be guaranteed to have integer
coordinates!
Input
Each test case will consist of six integers: X1, Y1, X2, Y2, X3, Y3 representing the three vertices
of a triangle. All the integers will be less than 100000 in absolute value.
Output
For each test case, output two integers on a single line - the coordinates of the point as
described in problem statement. If there is more than one solution, choose the one with smaller
X; if there is still a tie, choose the one with smaller Y.
Sample input
0 0 0 2 2 0
Sample output
1 1
Problem 2
Magic Square Solver
In recreational mathematics, a magic square of order n is an arrangement of n² numbers, usually
distinct integers, in a square, such that the n numbers in all rows, all columns, and both
diagonals sum to the same constant. Normal magic squares exist for all orders n ≥ 1 except n =
2, although the case n = 1 is trivial—it consists of a single cell containing the number 1. The
smallest nontrivial case, shown below, is of order 3.
Your task is to determine if the input is a magic square. You must determine if each row, column
and diagonal (only the two that cross opposite corners of the square) all sum to the same value.
Input
Input will consist of a series of values. The first value will be the size of the square, and the rest
will be the values of each cell in the square. The values of each cell in a row will be given in
order, with spaces between them, and there will be one row on each line.
Output
Output should consist of the word “Yes” or “No”, depending on whether or not the input is
indeed a magic square.
Sample input
3
2 7 6
9 5 1
4 3 8
Sample output
Yes
Sample input (2)
5
1 4 6 9 4
3 6 2 8 2
9 0 8 1 8
3 3 3 3 6
6 7 8 9 1
Sample output (2)
No
Problem 3
Walking Boxes
During the era of DOS games, point-and-click adventure games were able to gain a great deal of
popularity before fading away into obscurity, replaced by action games that made use of
hardware-accelerated graphics.
In a point-and-click adventure game, the player is able to walk their character around a room by
simply clicking where they want to go. One way this is accomplished is through the use of
walking boxes. For each room the player explores, in addition to the background image that is
visible to the player, there exist a series of connected boxes that the player is constrained to
walking within. Keeping the player within these boxes is a straightforward enough task, but
navigation from one box to another poses a problem. What if two boxes are not connected
directly; which intermediate boxes must his character pass through to arrive at his destination?
This problem can be solved through the use of a matrix. To get from one box to another,
successive lookups into the matrix will be made until the destination box is reached.
+--------+
|
4
|
+-+----+-+
+-------+
| 2 |
+-----------+
|
0
+---+----+---+
3
|
|
|
1
|
|
+-------+------------+-----------+
An example set of walking boxes.
From
For example, the layout shown above would produce the following matrix:
0
1
2
3
4
0
0
0
1
1
2
To
1 2
1 1
1 2
1 2
1 1
2 2
3
1
3
1
3
2
4
1
2
4
1
4
To get from box 0 to box 4, the game engine will look up the element at row 0 and column 4,
which is 1, and therefore the character will first proceed to box 1. The lookup for getting from
box 1 to box 4 will yield the value 2, so the character will continue to box 2. The next lookup will
yield the value 4, which is the number of the destination box, so when the character moves there
no further lookups will be required.
Write a program that generates one of these walking box matrices. You will be given a set of
boxes and the connections between them. The boxes will never form loops or be isolated from
each other, so there will always be exactly one path from one box to another, assuming that
paths do not double back on themselves.
Input
Input will consist of a box count on the first line. Whatever this number is, it will be followed by
exactly that many additional lines. Each of these lines will specify the other boxes one box is
connected to (the first line will be for box 0, the next for box 1, etc.).
Output
Output will consist of the walking boxes matrix that may be used for the purposes of navigation
as detailed above. Column and row labels should not be included; only the contents of the matrix
are required.
Sample input
5
1
0 2 3
1 4
1
2
Sample output
0 1 1 1 1
0 1 2 3 2
1 1 2 1 4
1 1 1 3 1
2 2 2 2 4
Problem 4
Adding Fractions
Write a program that inputs two fractions in the form a/b and c/d, and outputs their sum in the
form p/q reduced to its simplest form.
Input:
Two lines of input
ab
cd
where a/b and c/d represent the two input fractions.
Output:
Produce the output in the form
pq
where p/q represents the output fraction in simplest form.
Sample Input:
5 6
1 10
Sample Output:
14 15
Problem 5
Die Hard Problem
Assume you are given a set of receptacles of integer capacity c1, c2, ..., cn.
e.g.: 3, 5, 7, 11
These receptacles can contain water up to their capacity. Let xi be the content of receptacle i.
Consider the following rules:
Any receptacle can be filled with water or just emptied in a big sink:
empty(i) { xi = 0; }
fill(i) { xi = ci }
Pick two receptacles i and j of capacities ci and cj. Then you can pour one receptacle into
the other until either the source is empty or the recipient is full:
pour(i,j)
{
yj = cj - xj;
if ( xi <= yj ) {
xj = xj + xi;
xi = 0;
}
else {
xj = cj;
xi = xi - yj;
}
}
After a finite number of applications of those rules each receptacle will contain an integer
amount of water between 0 and its capacity. The total amount of water in the system
will then be: x1 + x2 + ... + xn.
Write a program that takes as input a sequence of integer capacities and a quantity to achieve
and determines, if it exists, a sequence of operations (empty, fill, pour) that leaves the system
with an amount of water equal to the given quantity.
Input
Input will consist of a series of arguments, the first of which being the quantity to achieve q
where 0<= q <= c1 + c2 + ... + cn. The remaining arguments will be the integer capacities of
the receptacles c1, c2, …, cn.
Output
Output should consist of a sequence of operations as defined above.
Sample input
diehard.exe 4 3 5
Sample output
fill(2)
pour(2,1)
empty(1)
pour(2,1)
fill(2)
pour(2,1)
Problem 6
Identity Checker
Write a program P that reads a text file and determines whether file just read is equal to the
source code of P itself. P cannot read from any other file or device.
Input
Input will consist of one file name, and that is the only file the program will be allowed to open.
Output
Output will consist of the word “Yes” or “No” depending on whether the file provided is equal to
the source code of the program.
Sample input
identity.exe compare.txt
Sample input file (compare.txt)
Is this the source code of the program?
Sample output
No
Problem 7
ChaininGame
One popular party game involves one person thinking of a word and then each person afterward
thinking of a different word which relates in some way. In some versions of the game, the words
are related by the letters in them; the first letter of the new word must be the same as the last
letter of the old word. These kinds of constructions are called “word chains”, and the more words
you use, the harder it gets to put them together.
Write a program that is able to take a list of words and determine if the entire set of these words
could be used in a single word chain, with each word used exactly once. For instance, the words
“Carpenter”, “Thread”, and “Ratchet” would be a valid list of words, because they can be
combined into a single chain (“CarpenteRatcheThread”), but “Yard”, “Denmark”, and “Cheese”
would not, because “Cheese” can’t connect to either “Yard” or “Denmark”.
Input
Input will consist of several words, separated by spaces. These words should be able to
interchange uppercase and lowercase freely; “cabin” should be processed identically to “CaBiN”.
Output
The output can take one of two forms. If the program finds that it is impossible to create a chain,
it should simply print out the word “Impossible”. If a chain is found, the program should print out
this chain, in order. Let the case of the connecting letter be determined by the word on the right.
Sample input
Carpenter threaD RatcheT
Sample output
CarpenteRatchethreaD
Problem 8
Budget Travel
An American travel agency is sometimes asked to estimate the minimum cost of traveling from
one city to another by automobile. The travel agency maintains lists of many of the gasoline
stations along the popular routes. The list contains the location and the current price per gallon
of gasoline for each station on the list.
In order to simplify the process of estimating this cost, the agency uses the following rules of
thumb about the behavior of automobile drivers.
A driver never stops at a gasoline station when the gasoline tank contains more than half
of its capacity unless the car cannot get to the following station (if there is one) or the
destination with the amount of gasoline in the tank.
A driver always fills the gasoline tank completely at every gasoline station stop.
When stopped at a gasoline station, a driver will spend $2.00 on snacks and goodies for
the trip.
A driver needs no more gasoline than necessary to reach a gasoline station or the city
limits of the destination.
A driver always begins with a full tank of gasoline.
The amount paid at each stop is rounded to the nearest cent (where 100 cents make a
dollar).
You must write a program that estimates the minimum amount of money that a driver will pay
for gasoline and snacks to make the trip.
Input
Input will consist of several lines of information. The first 2 lines give information about the origin
and destination. The remaining lines of the data set represent the gasoline stations along the
route, with one line per gasoline station. The following shows the exact format and meaning of
the input data.
Line 1: One real number N the distance from the origin to the destination
Line 2: Three real numbers followed by an integer
The first real number is the gallon capacity of the automobile’s fuel tank.
The second is the miles per gallon that the automobile can travel.
The third is the cost in dollars of filling the automobile’s tank in the origination city.
The integer (less than 51) is the number of gasoline stations along the route.
Each remaining line: Two real numbers
The first is the distance in miles from the origination city to the gasoline station.
The second is the price (in cents) per gallon of gasoline sold at that station.
All data will be positive. Gasoline stations along a route are arranged in nondescending order of
distance from the origin. No gasoline station along the route is further from the origin than the
distance from the origin to the destination. There are always enough stations appropriately
placed along the each route for any car to be able to get from the origin to the destination.
Output
Output should consist of the minimum total cost of the gasoline and snacks rounded to the
nearest cent. That total cost must include the initial cost of filling the tank at the origin.
Sample input
475.6
11.9 27.4 14.98 6
102.0 99.9
220.0 132.9
256.3 147.9
275.0 102.9
277.6 112.9
381.8 100.9
Sample output
$27.31
Sample input (2)
516.3
15.7 22.1 20.87 3
125.4 125.9
297.9 112.9
345.2 99.9
Sample output (2)
$38.09
Problem 9
Sudoku Solver
In the last decade, the Sudoku craze has spread from Japan to Britain and has now gained
ubiquity in America as well. Some publishers of Sudoku puzzle-books use computer programs to
generate their puzzles because it is faster and cheaper than having them created by hand.
For the uninitiated, a normal Sudoku problem consists of a 9x9 grid of cells made up of nine
smaller 3x3 grids called regions. The puzzle begins with the grid partially filled with digits, and it
is the job of the solver to fill in the blank spaces. The rule for filling in these cells is simple: each
of the nine rows, columns, and regions must contain the digits 1-9, with no repetitions, one in
each cell.
There are several techniques that can be used to solve Sudoku puzzles; one of the simplest is
called cross-hatching. Cross hatching involves looking a region and trying to find the location of a
missing numeral by eliminating rows and columns (that pass through the region) that already
contain it. Cells within the region that already contain digits, obviously, can be eliminated as well.
In the puzzle above, the location of the numeral 5 in the upper-right region can be deduced by
eliminating the rows and columns already containing a 5 and their associated cells in that region.
Obviously, it cannot go in the cell already filled with the numeral 6, which leaves only one
possible location: the lower left cell.
Difficult puzzles require more techniques to be solved - some requiring more advanced levels of
logical deduction, the hardest requiring deduction through trial-and-error. For this problem, you
will only be given puzzles classified as “easy”, each of which can be solved though cross-hatching
or a similar technique. Write a program that solves these problems. The particular method(s) it
uses will have no impact on your score.
Input
Input will consist of one file name, and that file will contain one Sudoku puzzle. The file will be
plaintext, with one row of the puzzle on each line. Blank cells will be denoted by a ‘.’ (period)
character, and cells containing numerals will simply be represented by digits.
Output
Acceptable output will consist of the solved Sudoku puzzle in the same format.
Sample input
puzzle.txt
Sample input file (puzzle.txt)
53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
Sample output
534678912
672195348
198342567
859761423
426853791
713924856
961537284
287419635
345286179
© Copyright 2026 Paperzz