Upload
candace-davis
View
214
Download
0
Embed Size (px)
Citation preview
ACM reminders
October 30 -- HMC Mock contest
Good times ?
November 10 -- ACM contest
November 13 -- Final acm class & contest wrap-up
Pending Azusa Pacific University: 4Alpha2Omega Pending Brigham Young University -- Hawaii Campus: C-Siders 1 Pending Brigham Young University -- Hawaii Campus: C-Siders 2 Pending California Lutheran University: Java the Hut Pending California Lutheran University: Just Wanna Program Pending California Lutheran University: javac this.java Pending California State University Long Beach: Beach1 Pending California State University Long Beach: Beach2 Pending California State University Long Beach: Beach3 Pending California State University, Northridge: CSUN Red Pending California State University, Northridge: CSUN Black Pending California State University, Northridge: CSUN-3 Pending El Camino College: ECC Beta
Accepted Harvey Mudd College: HMC 1 Accepted Harvey Mudd College: HMC 2 Accepted Harvey Mudd College: HMC 3 Pending Mount San Antonio College: MtSAC@Voidies$qf Pending Mount San Antonio College: MtSAC@Floaties$qi Pending Riverside Community College: Platinum Pending Riverside Community College: The Code Machine Pending Riverside Community College: CodeBlue Pending University of California, San Diego: UCSD Rock Pending University of California, San Diego: UCSD Paper Pending University of California, San Diego: UCSD Scissors Pending University of Southern California: Trojan Horse Pending University of Southern California: Trojan Pride Pending University of Southern California: Trojans
current list of competitors
C++ Map
multimap#include <map>
map#include <map>
www.dinkumware.com/htm_cpl/index.html www.sgi.com/tech/stl/
set of key/value pairs
C++ Map
multimap#include <map>
map#include <map>
www.dinkumware.com/htm_cpl/index.html www.sgi.com/tech/stl/
set of key/value pairs
(implemented as a balanced binary tree)
C++ Map
multimap#include <map>
map#include <map>
www.dinkumware.com/htm_cpl/index.html www.sgi.com/tech/stl/
set of key/value pairs
(implemented as a balanced binary tree)Fast: searching by key
Slow: searching by value
C++ Map
#define MP make_pair
typedef pair<int,int> PII;
map<PII,int> m;
m[MP(0,1)] = 10;
m[MP(0,2)] = 17;
m[MP(1,2)] = 5;
m[MP(2,0)] = 12; // probably not worth it for graphs...
map<string,int> m; // definitely worth it here
m[“ArcOS”] = 110; // as an associative array
m[“TheoComp”] = 140;
multimap<string,string> d; // as a dictionary
d.insert(MP(“fun”,“c++ coding”)); // methods exist to get
d.insert(MP(“fun”,“ACM coding”)); // all of “fun”s entries
0
2
110
17512
Geometric Problems
Problem 1 - Binary Space Partitions
observerBasic idea: draw objects from far (first) to near (last).
Geometric Problems
Problem 1 - Binary Space Partitions
observerBasic idea: draw objects from far (first) to near (last).
z
x
(0,-big)
(100,200)
(100,220)
(70,200)
(70,220)
(70,50)
(70,70)
(40,50)
(40,70)
(50,220)
(50,240)
(20,220)
(20,240)
(-30,210)
(-30,230)
(-60,210)
(-60,230)
(-20,60)
(-20,80)
(-50,60)
(-50,80)
A
BC
D
E
Geometric Problems
Problem 1 - Binary Space Partitions
Input: 54 -50 60 -20 60 -20 80 -50 804 -60 210 -30 210 -30 230 -60 2304 20 220 50 220 50 240 20 2404 70 200 100 200 100 220 70 2204 40 50 70 50 70 70 40 70
first part
Geometric Problems
Problem 1 - Binary Space Partitions
observerBasic idea: draw objects from far (first) to near (last).
z
x
(0,-big)
(100,200)
(100,220)
(70,200)
(70,220)
(70,50)
(70,70)
(40,50)
(40,70)
(50,220)
(50,240)
(20,220)
(20,240)
(-30,210)
(-30,230)
(-60,210)
(-60,230)
(-20,60)
(-20,80)
(-50,60)
(-50,80)
A
BC
D
E
(0,140)
(-15,0)
Geometric Problems
Problem 1 - Binary Space Partitions
observer
Basic idea: draw objects from far (first -- LEFT) to
near (last -- RIGHT).
z
x
(0,-big)
A
BC
D
E
(0,140)
(-15,0)
ABCDE
Geometric Problems
Problem 1 - Binary Space Partitions
observer
Basic idea: draw objects from far (first -- LEFT) to
near (last -- RIGHT).
z
x
(0,-big)
A
BC
D
E
(0,140)
(-15,0)
ABCDE
(70,150)
(-70,150)
A BCDE
Geometric Problems
Problem 1 - Binary Space Partitions
Input: 54 -50 60 -20 60 -20 80 -50 804 -60 210 -30 210 -30 230 -60 2304 20 220 50 220 50 240 20 2404 70 200 100 200 100 220 70 2204 40 50 70 50 70 70 40 7020 140 -15 070 150 -70 150
first part
second part
Geometric Problems
Problem 1 - Binary Space Partitions
Input: 54 -50 60 -20 60 -20 80 -50 804 -60 210 -30 210 -30 230 -60 2304 20 220 50 220 50 240 20 2404 70 200 100 200 100 220 70 2204 40 50 70 50 70 70 40 7020 140 -15 070 150 -70 150
first part
second part
Output: ECDAB the objects, in the order they would be rendered by this BSP
Geometric Problems
Problem 2 - Visualizing cubes
3 3 1
3 1
2
Geometric Problems
Problem 2 - Visualizing cubes
3 3 1
3 1
2
Suppose you rotate so that
left wall right wall
floor
left wall floor
floor right wall
right wall left wall
What is the resulting stacking pattern?
Geometric Problems
Problem 2 - Visualizing cubes
3 3 1
3 1
2
Suppose you rotate so that
left wall right wall
floor
left wall floor
floor right wall
right wall left wall
What is the resulting stacking pattern?
3 2 1
2 1 1
2 1
Geometric Problems
Problem 2 - Visualizing cubes
?!?
All-pairs shortest paths
A
B
ED
C
8
13
1
6
12
9
7 0
11
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
A B C D E
from
to
“Floyd-Warshall algorithm”
All-pairs shortest paths
A
B
ED
C
8
13
1
6
12
9
7 0
11
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
A B C D E
from
to
“Floyd-Warshall algorithm”
D0 = (dij )0
dij = shortest distance from i to j through nodes {1, …, k} k
dij = shortest distance from i to j through no nodes 0
All-pairs shortest paths
A
B
ED
C
8
13
1
6
12
9
7 0
11
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
A B C D E
from
to
“Floyd-Warshall algorithm”
D0 = (dij )0
dij =k
dij = shortest distance from i to j through nodes {1} 1
All-pairs shortest paths...
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D0 = (dij )0
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D1 = (dij )1
dij = shortest distance from i to j through nodes {1, …, k} k
dij =k
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 15 0 0 8
- - - 11 0
AB
C
D
E
“Floyd-Warshall algorithm”
All-pairs shortest paths...
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D0 = (dij )0
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D1 = (dij )1
dij = shortest distance from i to j through {1, …, k} k
dij =k
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 15 0 0 8
- - - 11 0
AB
C
D
E
“Floyd-Warshall algorithm”
All-pairs shortest paths...
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D0 = (dij )0
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 - 0 0 -
- - - 11 0
AB
C
D
E
D1 = (dij )1
dij = shortest distance from i to j through {1, …, k} k
dij =k
0 8 13 - 1- 0 - 6 12
- 9 0 - -
7 15 0 0 8
- - - 11 0
AB
C
D
E
“Floyd-Warshall algorithm”
All-pairs shortest paths...
0 8 13 14 1- 0 - 6 12
- 9 0 15 21
7 15 0 0 8
- - - 11 0
AB
C
D
E
D2 = (dij )2
0 8 13 14 1- 0 - 6 12
- 9 0 15 21
7 9 0 0 8
- - - 11 0
AB
C
D
E
D3 = (dij )3
0 8 13 14 113 0 6 6 12
22 9 0 15 21
7 9 0 0 8
18 20 11 11 0
AB
C
D
E
D4 = (dij )4
AB
C
D
E
D5 = (dij )5
to store the path, another matrix can track the last intermediate vertex
0 8 12 12 113 0 6 6 12
22 9 0 15 21
7 9 0 0 8
18 20 11 11 0