Presentation is loading. Please wait.

Presentation is loading. Please wait.

I couldn’t think of anything to put here. So have a cow. Or two.

Similar presentations


Presentation on theme: "I couldn’t think of anything to put here. So have a cow. Or two."— Presentation transcript:

1 I couldn’t think of anything to put here. So have a cow. Or two.

2 PotW Solution Problem recap: Determine the ancestors of a node in an organization graph. Given a list of employee to boss relationships and a list of queries, determine who must obey whom from the list of queries.

3 PotW Solution HashMap boss = new HashMap (); int groupN = scan.nextInt(); for (int i = 0 ; i < groupN; i++) { int employeeN = scan.nextInt(); String curBoss = scan.next(); for (int j = 0; j < employeeN; j++) { boss.put(scan.next(), curBoss); } int queryN = scan.nextInt(); for (int i = 0 ; i < queryN; i++) { String x = scan.next(), y = scan.next(); boolean isBoss = false; while (!isBoss && boss.containsKey(x)) { x = boss.get(x); isBoss = x.equals(y); } if (isBoss) { System.out.println("yes"); } else { System.out.println("no"); }

4 Gunn Programming Contest Was last Saturday! A Lynbrook team placed first! Congratulations to: o Steven Hao o Tony Jiang o Qingqi Zeng Missed the Gunn contest? Fear not, because there’s still…

5 Harker Invitational March 17, 9AM – 4PM Participation worth 30 points PotW credit (subject to change) Register at o Registration deadline - March 10 If anyone’s has a parent willing to chaperone, us

6 March USACO Is this coming weekend (March 2-5) o You know what that means! o (yes, the usual 5 points PotW credit for a 3-hour contest) Take it!

7 February USACO Problems I could have used this on the title slide…

8 Bronze – Rope Folding Farmer John has a rope of length L (1 <= L <= 10,000) with N (1 <= N <= 100) knots tied at distinct locations, including at its two endpoints. Count the number of locations where the rope can be folded such that the knots on opposite strands all line up exactly with each other. Example:

9 Rope Folding - Solution Sort the knot locations, build an array of differences o 0, 2, 4, 6, 10 would become 2, 2, 2, 4 Any prefix or suffix of the difference array that is a palindrome corresponds to a valid fold (ex: 2, 2; 2, 2, 2) Bounds are small enough to brute force check for palindromes

10 Silver – Overplanting Given N (1 <= N <= 1000) different axially-aligned, possibly overlapping rectangular regions (all coordinates between and 10 8 ), determine the total area covered by these regions. (Result may be larger than a 32-bit int)

11 Overplanting - Solution Use a “sweep line” approach: Sort all y-coordinates in scene, divide space into horizontal “slices” o Store the height of each slice as well as an “overlap count” for each slice Sort all x-coordinates, sweep across plane from left to right o When leading vertical edge of rectangle hit, increment “overlap count” of all slices covered by rectangle o When trailing vertical edge hit, decrement overlap counts o Maintains current number of “active” rectangles within each slice To compute total area, add up area of slices w/ positive overlap counts

12 Gold – Symmetry How many lines of symmetry are there between N < 1000 cows (with integer coordinates) on the 2D plane? First, how do we check if a certain line works? o Given a line, use vector geometry to reflect each point P over to a point Q o Use a set to check if point Q exists quickly Let m be the center of mass of the points o Then simply check every line PM o In order to take care of special cases, also check the line that goes through M and is perpendicular to PM

13 PotW – Juggling Bessie the cow is performing an elaborate juggling act that requires her to juggle many objects, but now that the act is ending, she needs to drop them in a certain order. Given the current order of the N objects, tell her how many moves she needs to drop all of the objects. A “move” is a left cyclic shift. For example, {3, 2, 1} is juggled to become {2, 1, 3}, {2, 1, 3} becomes {1, 3, 2}, 1 is dropped to make {3, 2}, which becomes {2, 3}, which becomes {3}, which becomes {}: 6 moves.

14 Juggling (cont.) Example Input: Output: 6 For 25 points, solve for N < 1,000 For 50 points, solve for N < 100,000 Time limit: 2 seconds


Download ppt "I couldn’t think of anything to put here. So have a cow. Or two."

Similar presentations


Ads by Google