9
DECEMBER 8 TH , 2008 Lynbrook Computer Science

DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

Embed Size (px)

Citation preview

Page 1: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

DECEMBER 8TH, 2008

Lynbrook Computer Science

Page 2: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

Announcements

USACO December – tonight!ACSL #1 – next weekTopCoder Marathon Match – Wednesday

$5000 purse!

Page 3: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

USACO: How to stay under time-limit

Know when to brute force

Use custom tester

Identify slowest parts of program

Page 4: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

When to brute-force?

1 sec = ~ 1 million operations/iterations Depends on size/complexity of each iteration

Plug in max values, determine max possible states that will need to be tested

Page 5: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

Example

There are P (3 <= P <= 15) people. Given that the productivity of two people Pi and Pj working together is Wi_j (-1000 <= Wi_j <= 1000), what is the most productive group that can be formed?

How many states will we need to test, at most?

Page 6: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

There are 2^15 = 32,768 possible groups to be formed at most (with 15 people).

In each group, each person can either be in the group, or not in the group. Thus with P people the number of possible groups is 2^P.

We can brute-force!

Page 7: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

USACO Custom Tester

USACO allows you to test your program with custom test data

Write a program to generate max size test data

Run it on USACO server to see if your program is fast enough

Page 8: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

Identifying slowest parts of a program

Nested loops = BAD!

Recursive functions: Check how many times they call themselves. E.g. Flood-fill recursion calls itself 8 times each time

(once for each direction)

Page 9: DECEMBER 8 TH, 2008 Lynbrook Computer Science. Announcements USACO December – tonight! ACSL #1 – next week TopCoder Marathon Match – Wednesday $5000 purse!

Improving algorithms?

Nested loops: Devise a new algorithm that has fewer nested loops

Recursion: Can the solution be found with an iterative algorithm? (Usually, it can)