1 / 14

I couldn’t think of anything to put here.

I couldn’t think of anything to put here. So have a cow. Or two. 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.

dimaia
Download Presentation

I couldn’t think of anything to put here.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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<String, String> boss = newHashMap<String, String>(); intgroupN = scan.nextInt(); for (inti = 0 ; i < groupN; i++) { intemployeeN = scan.nextInt(); String curBoss = scan.next(); for (int j = 0; j < employeeN; j++) { boss.put(scan.next(), curBoss); } } intqueryN = scan.nextInt(); for (inti = 0 ; i < queryN; i++) { String x = scan.next(), y = scan.next(); booleanisBoss = 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: • Steven Hao • Tony Jiang • 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 http://bit.ly/harkerproco12 • Registration deadline - March 10 • If anyone’s has a parent willing to chaperone, email us (officers@lynbrookcs.com)!

  6. March USACO • Is this coming weekend (March 2-5) • You know what that means! • (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 • 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 -108 and 108), 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” • 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 • When leading vertical edge of rectangle hit, increment “overlap count” of all slices covered by rectangle • When trailing vertical edge hit, decrement overlap counts • 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? • Given a line, use vector geometry to reflect each point P over to a point Q • Use a set to check if point Q exists quickly • Let m be the center of mass of the points • Then simply check every line PM • 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:33 2 1 • Output:6 • For 25 points, solve for N < 1,000 • For 50 points, solve for N < 100,000 • Time limit: 2 seconds

More Related