Download presentation

Presentation is loading. Please wait.

Published byAmelia O'Connell Modified over 2 years ago

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) (distance from 2 to 1 is 2) (distance from 2 to 1 is 2) (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: OR AND Consider the stack operations at the right. What is the result of the next pop? 3. is a binary operator whose value is the larger of its operands. Evaluate the prefix expression: push a push c push 's' push 'l' pop push 'u' pop push 's' push 'a' pop

8
P ROBLEM OR = AND = 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 = 2 5 = = = 8 Answer: 8

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google