110 likes | 230 Views
Gunn ProCo. Lynbrook 1st, 2nd, 3rd*, 4th. Results!. 1st: Johnny, MG, Victor (perfect score) 2nd: Julia, Tony, Jimmy (perfect score) 3rd: Team "Lynbrook High School" (Eugene Chen, Douglas Chen, Andrew He) 4th: Joshua, Dolly, Steven. Lessons learned. Making bugs wastes tons of time
E N D
Gunn ProCo Lynbrook 1st, 2nd, 3rd*, 4th
Results! • 1st: Johnny, MG, Victor (perfect score) • 2nd: Julia, Tony, Jimmy (perfect score) • 3rd: Team "Lynbrook High School" (Eugene Chen, Douglas Chen, Andrew He) • 4th: Joshua, Dolly, Steven
Lessons learned • Making bugs wastes tons of time • Pay attention to small details • The problem statements might have errors • Life is tough. Deal with it. • No penalty for wrong submissions: just keep trying • C++ I/O is annoying • Be on Johnny's team
Cow Placement • N seats • K antisocial cows • Each cow picks the largest empty segment to sit in and sits in the middle of the segment • Break ties by choosing the leftmost segment/seat • E.g. N = 4 and K = 3 • _ _ _ _ • _ o _ _ • _ o o _ • o o o _ • Output is "o o o _"
Cow Placement: Solution • Need O(nlogn) time • Scanning through the empty segments and selecting the largest one every time is too slow • O(n^2) • Instead, use a priority queue that stores empty segments • Start by pushing (1, N) into the queue • Use a custom comparator to sort by decreasing length, then increasing index
Custom Comparator (Java) public class Seg implements Comparable<Seg> { int a, b; public int len() { return b - a + 1; } public int compareTo(Seg& oth) { if (len() != oth.len()) return len() > oth.len() ? -1 : 1; if (a != oth.a) return a < oth.a ? -1 : 1; return 0; }
Custom Comparator (C++) typedef pair<int, int> pii; int len(pii a) { return a.second - a.first + 1; } struct comp { //priority_queue is a max-heap. bool operator()(pii& a, pii& b) { if (len(a) != len(b)) return len(a) > len(b); return a.first < b.first; } };
Disk Placement • 5 disks of diameter 100 • line segment of length 1000 • If the disks are randomly placed along the segment and all intersecting placements are discarded, what positions along the line will have the highest frequency?
Disk Placement: Solution • Just because the generated positions are random doesn't mean the frequencies are uniform! • Randomize the disks 1,000,000 times and keep track of valid positions • Use a histogram to visualize the densities • Or just use logic: • If you fix the leftmost and rightmost disks, then the highest probability of the disks not intersecting is if the leftmost and rightmost disks are at the extremities • Thus, the extremities should have the highest frequencies
Mathematica! Histogram[Reap[Sum[l = RandomInteger[999, 5]; If[Min[Abs[Differences[Sort[l]]]] >= 100, Sow /@ l; 1, 0], {i, 1, 10000000}]][[2, 1]], 50, ChartStyle -> {EdgeForm[None]}]
~No PotW~ All problems are available at https://s3-us-west-1.amazonaws.com/gunn2013/z34pg83ucq/prXY.pdf Where X = 2, 5, or 9 (point values) and Y = 1, 2, 3, or 4 (problem numbers)