Presentation is loading. Please wait.

Presentation is loading. Please wait.

HKOI 2012 (Junior) Q4 - Penicillin Gary Wong For any question, please ask via MSN:

Similar presentations


Presentation on theme: "HKOI 2012 (Junior) Q4 - Penicillin Gary Wong For any question, please ask via MSN:"— 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 (x i, y i ) can “grow” into an “unclean” square with side 2t at time t, with (x i, y i ) 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 <= x i, h <= P 0 <= y i, k <= Q

5

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

7 Statistics Disappointed…

8 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

9 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

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

11 Solution – 100% Consider the brown square Top-left corner: (x i – t, y i – t) Bottom-right corner: (x i + t, y i + t)

12 Solution – 100% But what if it reaches/exceeds boundaries? Actual top-left corner (max(0, x i – t), max(0, y i – t)) Actual bottom-right corner (min(P, x i + t), min(Q, y i + t))

13 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))

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

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

16 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) (c1, d1) (a2, b2) (c2, d2)

17 Solution – 100% How to detect the case of “no intersection”?

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

19 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

20 Any question?


Download ppt "HKOI 2012 (Junior) Q4 - Penicillin Gary Wong For any question, please ask via MSN:"

Similar presentations


Ads by Google