1 / 20

HKOI 2012 (Junior) Q4 - Penicillin

HKOI 2012 (Junior) Q4 - Penicillin. Gary Wong For any question, please ask via Email: garywong612@gmail.com MSN: gary_wong612@hotmail.com. For your interest (if any). The history in the problem is really true! Penicillin refers to a group of antibiotics Examples: Penicillin G

harlow
Download Presentation

HKOI 2012 (Junior) Q4 - Penicillin

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. HKOI 2012 (Junior)Q4 - Penicillin Gary Wong For any question, please ask via Email: garywong612@gmail.com MSN: gary_wong612@hotmail.com

  2. For your interest (if any) • The history in the problem is really true! • Penicillin refers to a group of antibiotics • Examples: • Penicillin G • Amoxicillin • Ampicillin • … • Bacteria and viruses are 2 different things

  3. Problem Statement • Each of N points (xi, yi) can “grow” into an “unclean” square with side 2t at time t, with (xi, yi) as the “centre” • A special point P(h, k) can “grow” into a square with side 2ts at time t • “Growth” is bounded by a rectangle with dimension P x Q • Area covered by square centred at P will be always clean

  4. Problem Statement • Find the area of unclean area • N.B.: Overlapped area should be counted repeatedly • Constraints: • 50% • N <= 50 • P, Q, s, t <= 100 • 100% • 1 <= N <= 10,000 • 1 <= P, Q, s, t <= 100,000 • 0 <= xi, h <= P • 0 <= yi, k <= Q

  5. Statistics • Max. score: 100 • No. of max: 2 • Std dev: 27.38 • Mean: 5.29 • Disappointed…

  6. Statistics • Disappointed…

  7. Solution – 50% • N <= 50 • P, Q, s, t <= 100 • How about declaring a 2D array to mimic the agar plate? • Simulate the growth step by step! • Count how many times each cell was covered, clear all sterile part • Complexity? • Very roughly, O(NPQt) • In fact much less than this

  8. Solution – 100% • 1 <= N <= 10,000 • 1 <= P, Q, s, t <= 100,000 • O(NPQt) cannot work anymore… • Note that • Each point is independent from each other, because overlapped areas are counted repeatedly • If you know how to do for one point, same for other (N-1) points

  9. Solution – 100% • The problem reduces to: • Given 2 “growing” squares, find the brown area without covered by green square

  10. Solution – 100% • Consider the brown square • Top-left corner: (xi – t, yi – t) • Bottom-right corner: (xi + t, yi + t)

  11. Solution – 100% • But what if it reaches/exceeds boundaries? • Actual top-left corner • (max(0, xi – t), max(0, yi – t)) • Actual bottom-right corner • (min(P, xi + t), min(Q, yi + t))

  12. Solution – 100% • Similarly, for green square, • Top-left corner • (max(0, h– st), max(0, k – st)) • Bottom-right corner • (min(P, h + st), min(Q, k + st))

  13. Solution – 100% • Next task: how to find intersection area between the 2 squares?

  14. Solution – 100% • Consider the corners of the intersection area! (a1, b1) (a2, b2) (c2, d2) (c1, d1)

  15. Solution – 100% • For the intersection area, • Top-left corner • (max(a1,a2), max(b1,b2)) • Bottom-right corner • (min(c1,c2), min(d1,d2)) (a1, b1) (a2, b2) (c1, d1) (c2, d2)

  16. Solution – 100% • How to detect the case of “no intersection”?

  17. Solution – 100% • Area of brown square minus area of intersection • Do this for N times • Complexity? • O(N)

  18. Common mistakes • Areas were not counted repeatedly • Cannot even pass the sample input in the problem • Misunderstand that penicillin can kill only one layer of bacteria • Forgot to use 64-bit integer type to store the answer

  19. Any question?

More Related