100 likes | 339 Views
Lynbrook Computer Science. Member Meeting, November 3, 2008. Upcoming Competitions. Thursday: TopCoder Single Round Match Fri-Mon (11/7-11/10): USACO November. Silicon Valley Code Camp. 117 different sessions Lots of different topics Java, .NET, UI Design, Web Programming, AJAX
E N D
Lynbrook Computer Science Member Meeting, November 3, 2008
Upcoming Competitions • Thursday: TopCoder Single Round Match • Fri-Mon (11/7-11/10): USACO November
Silicon Valley Code Camp • 117 different sessions • Lots of different topics • Java, .NET, UI Design, Web Programming, AJAX • This Saturday-Sunday, at Foothill College • Free! • siliconvalley-codecamp.com
Pasture Walk (From USACO Qual.) • N pastures (2-1000), numbered 1..N • Given connecting walkways and lengths • Find length of shortest path between given pastures. • Input:4 2 (4 pastures, 2 queries)2 1 2 (distance from 2 to 1 is 2)4 3 2 (distance from 2 to 1 is 2)1 4 3 (distance from 1 to 4 is 3)1 2 (query: distance from 1 to 2?)3 2 (query: distance from 3 to 2?)
Depth-First Search • For each pasture, store all outgoing paths • From each node, try all outgoing paths, except the one we came from • Use recursion! • Note: Only 1 possible path! Pasture 1 Pasture 2 Pasture 3 Pasture 4
Pseudo-code int query(int from, intdest, int source = -1) { for each path connected to pasture[start] { if (path.to == source) continue; // don’t go backwards if (path.to == dest) return path.dist; // we can see the goal int dist = query(path.to, dest, from); if (dist == -1) continue; // can’t reach goal with this path return dist + path.length; } return -1; // no valid path from this node }
ACSL Practice • 1. Evaluate the following: • 01011 OR 10110 AND 11010 • 2. Consider the stack operations at the right. What is the result of the next pop? • 3. Suppose @ is a binary operator whose value is the larger of its operands. Evaluate the prefix expression: • + @ 2 3 @ 4 @ 2 5 push ‘a’ push ‘c’ push 's' push 'l' pop push 'u' pop pop push 's' push 'a' pop pop
Problem 1 • 01011 OR 10110 = 11111 • 11111 AND 11010 = 11010 • Answer: 11010
Problem 2 STEP push ‘a’ push ‘c’ push 's' push 'l' pop push 'u' pop pop push 's' push 'a' pop pop STACK a c a s c a l s c a s c a u s c a s c a c a s c a a s c a s c a c a Next pop: C
Problem 3 • + @ 2 3 @ 4 @ 2 5 • @ 2 3 = 3 • @ 2 5 = 5 • + 3 @ 4 5 • @ 4 5 = 5 • + 3 5 • + 3 5 = 8 • Answer: 8