ACM reminders October 30 -- HMC Mock contest 9:00 - 12:30 November 10 -- regional contest This is...

Preview:

Citation preview

ACM reminders

October 30 -- HMC Mock contest 9:00 - 12:30

November 10 -- regional contest

This is the next ACM meeting !!

Contest-like problems

dynamic programming

graph algorithms

search and heuristic search

geometric problemssimulation problems

& AlgorithmsBFS, DFS, branch and bound

shortest paths, (max flow)

knapsack problem

HMC contest

When: 9:00 pm - 12:30 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 aren’t allowed

• teams may have 1-4 people & will be graded equally(first three teams of <= 3 students ACM)

Next time: contest

The following commands will be available in /cs/ACM/bin

Submission/Information:

• acm_submit <filename> -- 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

Strategy

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

Scoring

• a team’s 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

Scoring:

for example...

2 problems

5 hrs. 35 min.

submit problem 1 -- incorrect @ 45 min.

submit problem 2 -- correct @ 55 min.

submit problem 1 -- correct @ 1hr. 15 min.

Simulation Problems

Problem 1 - faa.cc Basic idea: use radar data to determine how close planes are to one another and print warnings

1 revolution / 4 seconds0º

75º

270º

planeA planeB

planeC

Radar sweep:

Simulation Problems

Problem 1 - faa.cc Basic idea: use radar data to determine how close planes are to one another and print warnings

1 revolution / 4 seconds0º

75º

270º

planeA planeB

planeC

Radar sweep:

Input Data

0 planeA 1 10000 0 0 0.2

bearing angle from 0 to 360

plane namehorizontal distance (feet)

elevation (feet)

heading angle from 0 to 360

horizontal velocity (ft/s)

ascent velocity (in ft/s)

Simulation Problems

Problem 1 - faa.cc Basic idea: use radar data to determine how close planes are to one another and print warnings

1 revolution / 4 seconds0º

75º

270º

planeA planeB

planeC

Radar sweep:

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

Simulation Problems

Problem 1 - faa.cc Basic idea: use radar data to determine how close planes are to one another and print warnings

1 revolution / 4 seconds0º

75º

270º

planeA planeB

planeC

Radar sweep:

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

Pairs of planes that will travel within 2500 feet of each other in the next 10 seconds.

Output

planeB planeA

planeC planeB

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

Input Data

top: +1

right: +2

bottom: +4

left: +8

WHEN OPEN

8+2 = A

4 3 A C 4 4 7 D 7 D 1 1 3 A

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

Input Data

top: +1

right: +2

bottom: +4

left: +8

WHEN OPEN

8+2 = A

4 3 A C 4 4 7 D 7 D 1 1 3 A

Output

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

Maze 1: The robots do not meet.

Maze 2: The robots meet in row 1, column 4.

Maze 3: The robots do not meet.

ACM reminders

October 30 -- HMC Mock contest 9:00 - 12:30

November 10 -- regional contest

This is the next ACM meeting !!

Contest-like problems

dynamic programming

graph algorithms

search and heuristic search

geometric problemssimulation problems

& AlgorithmsBFS, DFS, branch and bound

shortest paths, (max flow)

knapsack problem

HMC contest

When: 9:00 pm - 12:30 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 aren’t allowed

• teams may have 1-4 people & will be graded equally(first three teams of <= 3 students ACM)

Next time: contest

The following commands will be available in /cs/ACM/bin

Submission/Information:

• acm_submit <filename> -- 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

Strategy

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

Scoring

• a team’s 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

Scoring:

for example...

2 problems

5 hrs. 35 min.

submit problem 1 -- incorrect @ 45 min.

submit problem 2 -- correct @ 55 min.

submit problem 1 -- correct @ 1hr. 15 min.

Simulation Problems

Problem 1 - faa.cc Basic idea: use radar data to determine how close planes are to one another and print warnings

1 revolution / 4 seconds0º

75º

270º

planeA planeB

planeC

Radar sweep:

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

Pairs of planes that will travel within 2500 feet of each other in the next 10 seconds.

Output

planeB planeA

planeC planeB

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

“ro” “bot”clockwise counterclockwise

(when there is a choice to be made)

Simulation Problems

Problem 2 - roandbot.cc Basic idea: to see if two robots navigating a maze end up running into each other

Input Data

top: +1

right: +2

bottom: +4

left: +8

WHEN OPEN

8+2 = A

4 3 A C 4 4 7 D 7 D 1 1 3 A

Output

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

Maze 1: The robots do not meet.

Maze 2: The robots meet in row 1, column 4.

Maze 3: The robots do not meet.

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...

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

Other STL stuff

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

#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

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

Recommended