Presentation is loading. Please wait.

Presentation is loading. Please wait.

L YNBROOK C OMPUTER S CIENCE Member Meeting, November 3, 2008.

Similar presentations


Presentation on theme: "L YNBROOK C OMPUTER S CIENCE Member Meeting, November 3, 2008."— Presentation transcript:

1 L YNBROOK C OMPUTER S CIENCE Member Meeting, November 3, 2008

2 U PCOMING C OMPETITIONS Thursday: TopCoder Single Round Match Fri-Mon (11/7-11/10): USACO November

3 S ILICON V ALLEY C ODE C AMP 117 different sessions Lots of different topics Java,.NET, UI Design, Web Programming, AJAX This Saturday-Sunday, at Foothill College Free! siliconvalley-codecamp.com

4 P ASTURE W ALK (F ROM USACO Q UAL.) 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?)

5 D EPTH -F IRST S EARCH 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 4 Pasture 3

6 P SEUDO - CODE int query(int from, int dest, int source = -1) { for each path connected to pasture[start] { if (path.to == source) continue; // dont 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; // cant reach goal with this path return dist + path.length; } return -1; // no valid path from this node }

7 ACSL P RACTICE 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 push 's' push 'a' pop

8 P ROBLEM 1 01011 OR 10110 = 11111 11111 AND 11010 = 11010 Answer: 11010

9 P ROBLEM 2 STEP push a push c push 's' push 'l' pop push 'u' pop push 's' push 'a' 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

10 P ROBLEM 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


Download ppt "L YNBROOK C OMPUTER S CIENCE Member Meeting, November 3, 2008."

Similar presentations


Ads by Google