3.12 ≠ π

10
3.12 ≠ π What an inspiring title

description

3.12 ≠ π. What an inspiring title. PotW Solution - Bovinekiin. - PowerPoint PPT Presentation

Transcript of 3.12 ≠ π

Page 1: 3.12 ≠  π

3.12 ≠ πWhat an inspiring title

Page 2: 3.12 ≠  π

PotW Solution - Bovinekiin

int stall = 0;for (int i = 0; i < 90001; i++) { int a = rand.nextInt(n); int b = rand.nextInt(n); Item temp = cur.get(a); cur.set(a, cur.get(b)); cur.set(b, temp); if (calcGreedy(cur) > calcGreedy(best)) { best = new ArrayList<Item>(cur); // update best } else { cur = new ArrayList<Item>(best); // restore best stall++; if (stall == 9001) Collections.shuffle(cur); }}printSolution(best);• Full solution at http://ideone.com/yHPi6

Page 3: 3.12 ≠  π

About Harker• Deadline to register was last Saturday• You probably received an email with info if you’re

registeredo Read it!

• Scheduleo 8:30-9:30 Check-ino 9:30-10:30 Speakero 10:30-10:40 Breako 10:40-11:00 Diagnostics/Introduction to competition infrastructureo 11:00-12:30 Competitiono 12:30-1:45 Luncho 1:45-2:00 Set-up for Challenge Roundo 2:00-2:30 Challenge Roundo 2:30-3:00 Awards and Raffle

Page 4: 3.12 ≠  π

March USACOI know this title is off-center, but that’s

the way this slide theme works.

Page 5: 3.12 ≠  π

Bronze – Times 17• Given a number N, print 17 * N.

o The catch: Input and output are in binary, and N may have up to 1000 digits

• The solution: 17N = 16N + No 16N in binary is just N followed by four 0so Simple binary addition to add 16N to N

Page 6: 3.12 ≠  π

Silver – Flowerpot• Given the locations of N raindrops in the 2D

plane, compute the minimum width of a flowerpot along the x-axis such that the vertical distance between the first and last raindrop to hit the flowerpot is at least some value D.

• 1 <= N <= 100000• 1 <= D <= 1000000

Page 7: 3.12 ≠  π

Flowerpot – Solution• Sort all points by x-value, “sweep” a pair of

vertical lines from left to right• Store y-values of points between sweep lines in a

data structure that can easily find min and maxo Such as pair of priority queues

• Whenever difference btwn. min and max is at least D, check if this is best (min.) flowerpot width so far and advance left sweep line

• If not at least D, advance right sweep line

Page 8: 3.12 ≠  π

Gold – Skyscraper• Given an elevator with a weight capacity, what is the

minimal number of trips that will be needed to deliver n < 18 cows with certain weights from one floor of a skyscraper to the next. n < 18, so the solution is probably exponential in time

• Use dynamic programmingo The state is a bitmask of n bits: O(2n)o ith bit on: ith cow delivered, off: ith cow not delivered

• The DP function maps the bitmask to a pair of integers:o First, what's the minimum # of occupied elevators that must be used to

carry these cowso Second, what's the minimum amount of weight in the last elevator given

this minimal # of elevators

Page 9: 3.12 ≠  π

Skyscraper – Dynamic Programming

• This DP function only takes into account the weight of last elevator (weights in the other elevators are ignored)

• Minimize # of occupied elevators firsto Then minimize amount of weight in last elevatoro Basically just find the minimal pair lexicographically

• Base Case:o DP(all 0s) = (0, 0)

• Recurrence:o Try adding each non-used cow (of weight W) to the last elevator (adds

insignificant factor of O(n))o If it overflows the capacity, add a new elevator, and let the last elevator

have weight Wo If it doesn't, add W to the last elevator

Page 10: 3.12 ≠  π

No PotW this week!• Have fun at Harker this Saturday!