Vous êtes sur la page 1sur 12

break;

return; // to school :(

PotW Solution
Problem recap: Write a Befunge program that
prints out a Brain**** program that prints out a
HQ9+ program that prints out Hello, world!.
o HQ9+ program output by Brain**** program is H
o Brain**** program output by Befunge program may be +++++++++
+++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++. (including the dot at the end; there
are different ways to write this program but this is the simplest)
o Many ways to approach Befunge program

Example Solutions
20 characters (Andrew Wang)
89*
v
,"+"-1_v#:<
"
.
"
,
@

19 characters (Tony Jiang)


89*>:
v
^ , "+"-1_".",@

13 characters (Steven Hao)


"#>56++v
,:|
>
@

Announcements
ProCo on May 26, 8AM 5PM
o Registration is temporarily full until more space is found, but theres
a waiting list you can sign up for at http://proco.stanford.edu.

US Open/USACO results
o Congratulations to Steven Hao and Johnny Ho for placing 2nd and 3rd in
the country for US Open Gold division!
o Lynbrook students did very well in this years overall USACO rankings!
(Johnny Ho 1st in Gold, Steven Hao 9th in Gold, MG Chi 19th in Gold,
Qingqi Zeng 2nd in Silver, Karen Ouyang 4th in Silver, Julia Huang 18th in
Silver)
o Kudos to everyone who consistently participated in USACO this year!

USACO Finalists
o Special congratulations to Steven Hao for qualifying for the USACO
camp!
o Oh, and Johnny too.

Officer Applications
This years officer application will be made
available today!
o Check the website (http://lynbrookcs.com); also will be emailed

Due on Monday, May 14 at 11:59:59 PM


o Results will be announced on Monday, May 23

Same officer positions as this year:


o
o
o
o

1
1
1
1

president
vice president
secretary
treasurer

US Open
Lets have a look at some of the problems!

Bronze Three Lines


Given a set of up to n <= 50000 cows on the X-Y plane
with integer coordinates, determine if it is possible to
cover all the cows with three horizontal or vertical lines.
Create histogram of how many times each distinct ycoordinate appears as well as how many distinct ycoordinates there are
o Coordinates may have to be compressed first: normalize the coordinates to be
within the range [0, N) (or use HashMap)

Check 4 cases of what points can be covered by:


o 3 horizontal lines: Passes if number of distinct y-coordinates is as most 3
o 2 horizontal, 1 vertical: Sort points on x, for each distinct x-coordinate remove
all points with that x-coordinate (simulating vertical line there), test if number of
distinct y-coordinates drops to at most 2
o Other two cases identical to these two, except swap x and y

Silver Unlocking Blocks


Given the shapes and locations of three objects
(represented as series of the coordinates for the
individual boxes that form the shapes), determine
the minimum number of slides (one object moved
one tile north, east, south, or west) needed to
separate the blocks (bounding boxes no longer
overlap).

Silver Unlocking Blocks


Use depth/breadth-first search: find path from
initial state to state w/ disjoint bounding boxes
o Since we are not looking for any particular path, any of these graph
search algorithms works

Represent state with 4 integers (x and y offsets of


objects 2 and 3 from their original positions)
o Each move consists of adding/subtracting 1 from one of these
numbers, or adding/subtracting 1 from both x-coordinates or both ycoordinates (representing object 1 being moved)

DFS/BFS may quickly branch out but objects and


coordinates are small so its okay

Gold Tied Down


Given n <= 10 poles stuck in the ground and a
string that wraps around them, find the minimum
number of poles that must be removed before the
string can be untangled
o Obviously, the string cannot pass through poles unless they are
removed
o The poles are conveniently all on the same line (same x-coordinate)

Try removing all 210 subsets of the poles


o Find y coordinates of intersections between the string and the line
o Use a stack to simplify the crossings as you traverse the string
o If a string crosses across one portion of the line and then immediately
returns across the same portion, the string will then unwrap
o If the stack is completely emptied by the time the entire string has
been traversed, the string can be untangled

Gold Tied Down

PotW
No PotW this week study for AP exams if youre
taking any! (or finish that AP Lit research paper)
The Befunge problem marks the last PotW of this
school year
(or does it?)

Vous aimerez peut-être aussi