Download presentation
1
How to Pebbling Odometer
And beat Gennady Korotkevich
2
Pebbling Odometer (IOI 2012 #1)
IOI problems are not that hard* This problem is a variation on Karel The robot taught in Java Can't do much except turn, move, and get/put beepers The language specification is much more limited than Java's, however Very ad-hoc problem Tripped up Gennady Korotkevich (IOI 1st place ) Only one perfect score on this problem Not Johnny Ho (missed .14 points) Score rounds to nearest integer :D
3
Basic Operations Your odometer starts at (0, 0) and faces north
The +x axis points down and the +y axis points right left - turn left right - turn right (nicer than Karel!) move - move forward one get - remove one pebble put - put one pebble halt - exit # can be used as comment
4
Flow Operations [label name]: - this defines a label (position marker)
jump [label name] - move program execution to label border [label name] - if program is facing border, jump to label pebble [label name] - if current position has at least one pebble, jump to label
5
Basic loop start: pebble endloop move jump start endloop:
# this program moves the odometer forward until it lands on a pebble
6
Another example start: pebble getpebble_cont jump endloop
jump start endloop: # this program removes all pebbles from current position
7
Alright... subtask #1 [9 pts]
At the beginning there are x pebbles in cell (0, 0) and y in cell (0, 1), whereas all the other cells are empty. Write a program that terminates with the odometer in cell (0, 0) if x ≤ y, and in cell (0, 1) otherwise.
8
Solution Take pebble from (0, 0), and then take pebble from (0, 1)
Repeat If it's ever not possible to take a pebble from the position you’re currently on, exit.
9
Subtask #3 [19 pts] There are exactly two pebbles somewhere in row 0: one is in cell (0, x), the other in cell (0, y); x and y are distinct, and x + y is even. Write a program that leaves the odometer in cell (0, (x + y) / 2), i.e., exactly in the midpoint between the two cells containing the pebbles.
10
Solution Find first pebble (on the left) Add pebble to its right
Find next pebble (on the right) Add pebble to its left unless there's a pebble there already, in which case you exit Repeat
11
Subtask #5 [32 pts] There may be any number of pebbles in each cell of the grid (between 0 and 15). Write a program that finds the minimum, i.e., that terminates with the odometer in a cell (i, j) such that every other cell contains at least as many pebbles as (i, j). After running the program, the number of pebbles in each cell must be the same as before running the program. Graded based on # of commands in program :) Target was 444, Johnny got 449
12
Solution First case: minimum # of pebbles is 0
Scan through all locations in zigzag pattern If you find a location that has 0 pebbles, exit Second case: minimum # of pebbles is 1 For each location: Take away 1 pebble If the location has no pebbles left, put back pebbles and exit Put back pebbles [Repeat 13 more times]
13
Solution [cont.] Optimally, make a program that generates your program (label names must be unique) Need some more work to minimize code size Cascade putting back pebbles when exiting
14
PotW 15 points: solve subtask #1 20 points: solve subtask #3
Please note that you start facing north at (0, 0), and (x, y) means that the object is currently lying on row x and column y We'll be somewhat lenient since an interpreter is not yet available 30 points: write an interpreter for us too :)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.