Download DOC

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Halting problem wikipedia , lookup

Location arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
All-Ireland Schools Programming Competition
Round One Problems
Each of the following problems requires that you write a computer program to solve
it. Your program may accept input from the keyboard or from an input file and may
write output to the screen or to an output file. Be aware that in the official
competition, all input and output is done via input/output files to facilitate the
automatic program grading.
Problem 1 : Range
Write a program to input a sequence of numbers and output the minimum and
maximum values in the sequence.
Example:
How many numbers? : 8
Input numbers : 11 7 19 5 2 5 2 10
Minimum = 2
Maximum = 19
Problem 2 : Top Two
Write a program to input a sequence of numbers and output the sum of the two largest
values in the sequence.
Example:
How many numbers? : 8
Input numbers : 11 7 19 5 2 5 2 10
Sum of two largest values = 30
Problem 3: Two Rook moves
E00000
0G0GE0
G00000
000000
0R0000
The diagram above represents a 6x5 chess-board.
‘0’ is an empty square
‘R’ is your rook piece
‘G’ is a piece of gold
‘E’ is an exit.
Your objective is to move your rook piece to an exit in (at most) two moves, while
collecting the most amount of gold you can. For those not familiar with chess, a rook
move consists of moving the rook horizontally or vertically, to a position along its
current row or column, moving through each intermediate square. If your rook moves
through a square with a gold piece in it, the gold is collected. If your rook moves
through an exit square, your moves are finished and you then count your gold.
Your program should input the width and height of the chessboard and then input the
layout of the pieces on the board. It should output the maximum amount of gold that
can be collected before exiting.
Note: Your Rook may not retrace its steps or revisit any square it has already
passed through.
Example input:
10 10
0000E00000
0000GG00E0
0000G000G0
00000000G0
E000R0G0GE
0GGGGGG000
0GGGGGG000
0GGGGGG000
0GGGGGG000
0000E00000
Example output:
4
(There are two ways to collect four gold coins)
Problem 4: Volcano
While enjoying your holiday in the sun on a remote island, you suddenly realise that
the island’s previously dormant volcanoes have become active and will soon erupt!
Fortunately, due to scientific advancements you know exactly where the volcanoes
will erupt and how powerful their lava flows will be. It is also possible to predict very
accurately, using lava flow models, how the volcano’s lava will move.
The lava moves as follows:
The island is represented as a grid of squares. At a certain time, each square
has a value indicating how much lava it contains. For any given square, to calculate
how much lava it will contain one second later, add up its value and the values of its
four neighbouring squares (up, down, left and right), then divide by five. If the result
is not a whole number, round it down to the nearest integer. If any of its neighbours
are outside the island, they have a value of zero lava.
Example: A volcano of power 40 erupts as follows
0
0
0
0
0
0 0 0
0 0 0
0 40 0
0 0 0
0 0 0
(time=0)
0
0
0
0
0
0
0
0
0
0
0 0 0
0 8 0
8 8 8
0 8 0
0 0 0
(time=1)
0
0
0
0
0
0
0
1
0
0
0 1
3 3
3 8
3 3
0 1
(time=2)
0
3
3
3
0
0
0
1
0
0
0
0
0
0
0
0
1
3
1
0
0 0
3 1
4 3
3 1
0 0
(time=3)
0
0
0
0
0
0
0
0
0
0
0 0 0
1 1 1
1 3 1
1 1 1
0 0 0
(time=4)
0
0
0
0
0
0
0
0
0
0
0 0
0 1
1 1
0 1
0 0
(time=5)
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 0
0 0
1 0
0 0
0 0
(time=6)
0
0
0
0
0
0
0
0
0
0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
(time=7)
0
0
0
0
0
If the square you occupy contains lava, you will be burnt to a crisp instantly. You
must stay in a safe place until help can arrive. Therefore, your objective is to locate a
square that remains safe for the longest time. (i.e. a square remains safe from time=0
to time=T, so choose a square that maximises the value of T. Note: after time T, the
square may become safe again for a long time, but it doesn’t matter to you if you are
dead.)
The input to your program begins with W, H, the width and height of the island. The
next line contains N, the number of volcanoes, and each subsequent line contains four
numbers describing each volcano: its location, x, y, the time of eruption, t, and its
power, p.
Note:
- Position (1,1) represents the top left corner of the island.
- When a volcano erupts at time ‘t’, add its power to the lava flow at that
location.
- 3 <= W,H <= 100
- 0 <= T <= 1,000,000 (volcano eruption time)
- 0 <= P <= 65,000
(volcano power)
- 0 <= N <= 1,000
(number of volcanos)
Example input:
55
4
2205
3305
4405
5 1 2 10
0
0
0
0
0
0
5
0
0
0
0 0
0 0
5 0
0 5
0 0
(time=0)
0
0
0
0
0
0
1
0
0
0
1 0 0
1 2 0
2 1 2
0 2 1
0 0 1
(time=1)
0
0
0
1
0
0
0
0
0
0
0 0
1 0
0 1
0 0
0 0
(time=2)
0 10
0 0
0 0
1 0
0 0
0
0
0
0
0
0
0
0
0
0
0 2
0 0
0 0
0 0
0 0
(time=3)
2
2
0
0
0
0
0
0
0
0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
(time=4)
1
0
0
0
0
0
0
0
0
0
0 0
0 0
0 0
0 0
0 0
(time=5)
0
0
0
0
0
0 X 0
X X X
0 X X
0 0 X
0 0 0
(Solutions)
X
0
X
X
X
0
0
0
0
0
X
X
0
X
0
Any of the ‘0’ squares above remain safe throughout the whole eruption process and
they are all valid solutions. In some scenarios there may not be any squares that are
always safe. In that case choose the square that remains safe the longest, so that you
have the best chance of being rescued.
Example output:
11
Problem 5: Wormholes
In the year 2163, wormholes were discovered. A wormhole is a subspace tunnel
through space and time connecting two star systems. Wormholes have a few peculiar
properties:




Wormholes are one-way only.
The time it takes to travel through a wormhole is negligible.
A wormhole has two end points, each situated in a star system.
A star system may have more than one wormhole end point within its
boundaries.



For some unknown reason, starting from our solar system, it is always possible
to end up in any star system by following a sequence of wormholes (maybe
Earth is the centre of the universe).
Between any pair of star systems, there is at most one wormhole in either
direction.
There are no wormholes with both end points in the same star system.
All wormholes have a constant time difference between their end points. For example,
a specific wormhole may cause the person travelling through it to end up 15 years in
the future. Another wormhole may cause the person to end up 42 years in the past.
A brilliant physicist, living on earth, wants to use wormholes to study the Big Bang.
Since warp drive has not been invented yet, it is not possible for her to travel from one
star system to another one directly. This can be done using wormholes, of course.
The physicist wants to reach a cycle of wormholes somewhere in the universe that
causes her to end up in the past. By travelling along this cycle a lot of times, the
physicist is able to go back as far in time as necessary to reach the beginning of the
universe and see the Big Bang with her own eyes. Write a program to find out
whether such a cycle exists.
Input
The input file starts with two numbers n and m . These indicate the number of star
systems (1 <= n <= 1000) and the number of wormholes (0 <= m <= 2000) . The star
systems are numbered from 0 (our solar system) through n-1 . For each wormhole a
line containing three integer numbers x, y and t is given. These numbers indicate that
this wormhole allows someone to travel from the star system numbered x to the star
system numbered y, thereby ending up t (-1000 <= t <= 1000) years in the future.
Output
The output consists of 1 line containing the word possible if it is indeed possible to
go back in time indefinitely, or not possible if this is not possible with the given set
of star systems and wormholes.
Sample Input
3
0
1
2
3
1 1000
2 15
1 -42
Sample Output
possible
Sample Input
4
0
1
2
3
4
1
2
3
0
10
20
30
-60
Sample Output
not possible