Title: CS 60 Slides
1ACM reminders
October 30 -- HMC Mock contest 900 - 1230
This is the next ACM meeting !!
dynamic programming
knapsack problem
graph algorithms
Contest-like problems
shortest paths, (max flow)
Algorithms
search and heuristic search
BFS, DFS, branch and bound
geometric problems
simulation problems
November 10 -- regional contest
2HMC contest
When 900 pm - 1230 am on Tuesday, October
30
Where here (the graphics lab or in the
terminal room)
What 6 problems
Rules
- only one terminal/keyboard may be used by a team
- written material and references permitted, but
electronic resources or computer files arent
allowed - teams may have 1-4 people will be graded
equally (first three teams of lt 3 students
ACM)
3Next time contest
Submission/Information
The following commands will be available in
/cs/ACM/bin
- acm_submit ltfilenamegt -- submits a file for
testing - acm_standings -- gets the current standings
time remaining - acm_answers -- prints out written answers
corrections to problems
- Ask any questions directly. (The reg. contest
has a program for this.) - When a problem is submitted, we will check it by
hand and return one of the following messages
- Problem correct!
- Presentation error
- Wrong output
- Run-time error
- Did not compile
increasing severity
4Strategy
Look over the problems and decide a rough order
of difficulty.
When possible, code with someone looking over
your shoulder.
Trade off the job of writing code to the person
most familiar with the problem.
You can reuse any code written from the time the
contest starts.
- you may want to immediately code an I/O
skeleton or other routines
5Scoring
Scoring
- a teams score is two numbers - solved
problems - amount of time - rankings are based on the of solved
problems - ties are broken by time (less time is
better) - time sum of the of minutes from the contest
start to the solution of each solved problem - each incorrect submission of a problem incurs a
20 minute time penalty if that problem is
solved
2 problems
5 hrs. 35 min.
for example...
submit problem 1 -- incorrect _at_ 45 min. submit
problem 2 -- correct _at_ 55 min. submit problem 1
-- correct _at_ 1hr. 15 min.
6Simulation Problems
Basic idea use radar data to determine how close
planes are to one another and print warnings
Problem 1 - faa.cc
0º
Radar sweep
1 revolution / 4 seconds
75º
planeA
planeB
270º
planeC
7Simulation Problems
Basic idea use radar data to determine how close
planes are to one another and print warnings
Problem 1 - faa.cc
0º
Radar sweep
1 revolution / 4 seconds
75º
planeA
planeB
270º
horizontal velocity (ft/s)
planeC
Input Data
bearing angle from 0 to 360
0 planeA 1 10000 0 0 0.2
plane name
ascent velocity (in ft/s)
horizontal distance (feet)
heading angle from 0 to 360
elevation (feet)
8Simulation Problems
Basic idea use radar data to determine how close
planes are to one another and print warnings
Problem 1 - faa.cc
0º
Radar sweep
1 revolution / 4 seconds
75º
planeA
planeB
270º
planeC
Input Data
0 planeA 1 10000 0 0 0.2
75 planeB 5.79 10000 270 0 1
270 planeC 2500 10000 0 0 0.2
END OF INPUT
9Simulation Problems
Basic idea use radar data to determine how close
planes are to one another and print warnings
Problem 1 - faa.cc
0º
Radar sweep
1 revolution / 4 seconds
75º
planeA
planeB
270º
planeC
Input Data
Output
0 planeA 1 10000 0 0 0.2
75 planeB 5.79 10000 270 0 1
Pairs of planes that will travel within 2500 feet
of each other in the next 10 seconds.
planeB planeA planeC planeB
270 planeC 2500 10000 0 0 0.2
END OF INPUT
10Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
11Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
12Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
13Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
14Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
15Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
16Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
17Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
18Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
19Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
20Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
21Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
22Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
23Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
Input Data
82 A
4 3 A C 4 4 7 D 7 D 1 1 3 A
top 1
right 2
left 8
WHEN OPEN
bottom 4
24Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
Input Data
82 A
4 3 A C 4 4 7 D 7 D 1 1 3 A
3 7 C 4 2 E A E C 5 3 E 9 6 9 1 3 A B 8 3 A A
5 4 A E C 4 4 5 1 5 3 B A B 6 C 6 9 1 3 B A
0 0
Output
Maze 1 The robots do not meet. Maze 2 The
robots meet in row 1, column 4. Maze 3 The
robots do not meet.
top 1
right 2
left 8
WHEN OPEN
bottom 4
25ACM reminders
October 30 -- HMC Mock contest 900 - 1230
This is the next ACM meeting !!
dynamic programming
knapsack problem
graph algorithms
Contest-like problems
shortest paths, (max flow)
Algorithms
search and heuristic search
BFS, DFS, branch and bound
geometric problems
simulation problems
November 10 -- regional contest
26HMC contest
When 900 pm - 1230 am on Tuesday, October
30
Where here (the graphics lab or in the
terminal room)
What 6 problems
Rules
- only one terminal/keyboard may be used by a team
- written material and references permitted, but
electronic resources or computer files arent
allowed - teams may have 1-4 people will be graded
equally (first three teams of lt 3 students
ACM)
27Next time contest
Submission/Information
The following commands will be available in
/cs/ACM/bin
- acm_submit ltfilenamegt -- submits a file for
testing - acm_standings -- gets the current standings
time remaining - acm_answers -- prints out written answers
corrections to problems
- Ask any questions directly. (The reg. contest
has a program for this.) - When a problem is submitted, we will check it by
hand and return one of the following messages
- Problem correct!
- Presentation error
- Wrong output
- Run-time error
- Did not compile
increasing severity
28Strategy
Look over the problems and decide a rough order
of difficulty.
When possible, code with someone looking over
your shoulder.
Trade off the job of writing code to the person
most familiar with the problem.
You can reuse any code written from the time the
contest starts.
- you may want to immediately code an I/O
skeleton or other routines
29Scoring
Scoring
- a teams score is two numbers - solved
problems - amount of time - rankings are based on the of solved
problems - ties are broken by time (less time is
better) - time sum of the of minutes from the contest
start to the solution of each solved problem - each incorrect submission of a problem incurs a
20 minute time penalty if that problem is
solved
2 problems
5 hrs. 35 min.
for example...
submit problem 1 -- incorrect _at_ 45 min. submit
problem 2 -- correct _at_ 55 min. submit problem 1
-- correct _at_ 1hr. 15 min.
30Simulation Problems
Basic idea use radar data to determine how close
planes are to one another and print warnings
Problem 1 - faa.cc
0º
Radar sweep
1 revolution / 4 seconds
75º
planeA
planeB
270º
planeC
Input Data
Output
0 planeA 1 10000 0 0 0.2
75 planeB 5.79 10000 270 0 1
Pairs of planes that will travel within 2500 feet
of each other in the next 10 seconds.
planeB planeA planeC planeB
270 planeC 2500 10000 0 0 0.2
END OF INPUT
31Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
ro
bot
clockwise
counterclockwise
(when there is a choice to be made)
32Simulation Problems
Basic idea to see if two robots navigating a
maze end up running into each other
Problem 2 - roandbot.cc
Input Data
82 A
4 3 A C 4 4 7 D 7 D 1 1 3 A
3 7 C 4 2 E A E C 5 3 E 9 6 9 1 3 A B 8 3 A A
5 4 A E C 4 4 5 1 5 3 B A B 6 C 6 9 1 3 B A
0 0
Output
Maze 1 The robots do not meet. Maze 2 The
robots meet in row 1, column 4. Maze 3 The
robots do not meet.
top 1
right 2
left 8
WHEN OPEN
bottom 4
33Geometric Problems
Problem 1 - Binary Space Partitions
z
(50,240)
(20,240)
C
(-30,230)
(-60,230)
(100,220)
(70,220)
B
(50,220)
(20,220)
D
(-30,210)
(-60,210)
(100,200)
(70,200)
(-20,80)
(-50,80)
A
(70,70)
(40,70)
E
(-20,60)
(-50,60)
(70,50)
(40,50)
x
Basic idea draw objects from far (first) to near
(last).
(0,-big)
observer
34Geometric Problems
Problem 1 - Binary Space Partitions
Input
5 4 -50 60 -20 60 -20 80 -50 80 4 -60 210 -30 210
-30 230 -60 230 4 20 220 50 220 50 240 20 240 4
70 200 100 200 100 220 70 220 4 40 50 70 50 70 70
40 70
first part
35Geometric Problems
Problem 1 - Binary Space Partitions
z
(50,240)
(20,240)
C
(-30,230)
(-60,230)
(100,220)
(70,220)
B
(50,220)
(20,220)
D
(-30,210)
(-60,210)
(100,200)
(70,200)
(0,140)
(-20,80)
(-50,80)
A
(70,70)
(40,70)
E
(-20,60)
(-50,60)
(70,50)
(40,50)
(-15,0)
x
Basic idea draw objects from far (first) to near
(last).
(0,-big)
observer
36Geometric Problems
Problem 1 - Binary Space Partitions
z
C
B
D
(0,140)
A
E
AB
CDE
(-15,0)
x
Basic idea draw objects from far (first -- LEFT)
to near (last -- RIGHT).
(0,-big)
observer
37Geometric Problems
Problem 1 - Binary Space Partitions
z
C
B
D
(-70,150)
(70,150)
(0,140)
A
E
AB
CDE
A
B
CD
E
(-15,0)
x
Basic idea draw objects from far (first -- LEFT)
to near (last -- RIGHT).
(0,-big)
observer
38Geometric Problems
Problem 1 - Binary Space Partitions
Input
5 4 -50 60 -20 60 -20 80 -50 80 4 -60 210 -30 210
-30 230 -60 230 4 20 220 50 220 50 240 20 240 4
70 200 100 200 100 220 70 220 4 40 50 70 50 70 70
40 70 2 0 140 -15 0 70 150 -70 150
first part
second part
39Geometric Problems
Problem 1 - Binary Space Partitions
Input
5 4 -50 60 -20 60 -20 80 -50 80 4 -60 210 -30 210
-30 230 -60 230 4 20 220 50 220 50 240 20 240 4
70 200 100 200 100 220 70 220 4 40 50 70 50 70 70
40 70 2 0 140 -15 0 70 150 -70 150
first part
second part
the objects, in the order they would be rendered
by this BSP
Output
ECDAB
40Geometric Problems
Problem 2 - Visualizing cubes
3 3 1 3 1 2
41Geometric Problems
Problem 2 - Visualizing cubes
3 3 1 3 1 2
left wall
right wall
floor
left wall
floor
Suppose you rotate so that
floor
right wall
right wall
left wall
What is the resulting stacking pattern?
42Geometric Problems
Problem 2 - Visualizing cubes
3 3 1 3 1 2
left wall
right wall
floor
left wall
floor
Suppose you rotate so that
floor
right wall
3 2 1 2 1 1 2 1
right wall
left wall
What is the resulting stacking pattern?
43Geometric Problems
Problem 2 - Visualizing cubes
?!?
44All-pairs shortest paths...
Floyd-Warshall algorithm
A
B
k
dij
C
D
E
0
D0 (dij )
A
0
8
13
-
1
A
B
-
0
-
6
12
B
C
-
9
0
-
-
C
D
7
15
0
0
8
D
E
-
-
-
11
0
E
1
D1 (dij )
k
dij shortest distance from i to j through
nodes 1, , k
45All-pairs shortest paths...
Floyd-Warshall algorithm
A
B
k
dij
C
D
E
0
D0 (dij )
A
0
8
13
-
1
A
B
-
0
-
6
12
B
C
-
9
0
-
-
C
D
7
15
0
0
8
D
E
-
-
-
11
0
E
1
D1 (dij )
k
dij shortest distance from i to j through
1, , k
46All-pairs shortest paths...
Floyd-Warshall algorithm
A
B
k
dij
C
D
E
0
D0 (dij )
A
0
8
13
-
1
A
B
-
0
-
6
12
B
C
-
9
0
-
-
C
D
7
15
0
0
8
D
E
-
-
-
11
0
E
1
D1 (dij )
k
dij shortest distance from i to j through
1, , k
47All-pairs shortest paths...
0
8
13
14
1
A
0
8
13
14
1
A
13
0
6
6
12
B
-
0
-
6
12
B
22
9
0
15
21
C
-
9
0
15
21
C
7
9
0
0
8
D
7
15
0
0
8
D
18
20
11
11
0
E
-
-
-
11
0
E
4
D4 (dij )
2
D2 (dij )
A
0
8
13
14
1
A
0
8
12
12
1
B
-
0
-
6
12
B
13
0
6
6
12
C
-
9
0
15
21
C
22
9
0
15
21
D
7
9
0
0
8
D
7
9
0
0
8
E
-
-
-
11
0
E
18
20
11
11
0
5
3
D5 (dij )
D3 (dij )
to store the path, another matrix can track the
last intermediate vertex
48Other STL stuff
www.dinkumware.com/htm_cpl/index.html
www.sgi.com/tech/stl/
map
multimap
include ltmapgt
include ltmapgt
set of key/value pairs
49C Map
define MP make_pair typedef pairltint,intgt
PII mapltPII,intgt m mMP(0,1) 10 mMP(0,2)
17 mMP(1,2) 5 mMP(2,0) 12 //
probably not worth it for graphs... mapltstring,int
gt m // definitely worth it
here mArcOS 110 // as an
associative array mTheoComp
140 multimapltstring,stringgt d // as a
dictionary d.insert(MP(fun,c coding)) //
methods exist to get d.insert(MP(fun,ACM
coding)) // all of funs entries
10
0
1
17
5
12
2
50All-pairs shortest paths
Floyd-Warshall algorithm
B
8
9
to
A
D
E
A
B
C
13
C
A
6
B
0
C
from
7
1
12
D
D
E
E
11
51All-pairs shortest paths
Floyd-Warshall algorithm
B
8
9
to
A
D
E
A
B
C
13
C
A
6
B
0
C
from
7
1
12
D
D
E
E
11
0
D0 (dij )
0
dij shortest distance from i to j through no
nodes
k
dij shortest distance from i to j through
nodes 1, , k
52All-pairs shortest paths
Floyd-Warshall algorithm
B
8
9
to
A
D
E
A
B
C
13
C
A
6
B
0
C
from
7
1
12
D
D
E
E
11
0
D0 (dij )
1
dij shortest distance from i to j through
nodes 1
k
dij