27
Storage Centre Storage Centre HKOI 2007 Senior Q1 HKOI 2007 Senior Q1 Kelly Choi Kelly Choi

Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Embed Size (px)

Citation preview

Page 1: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Storage CentreStorage Centre

HKOI 2007 Senior Q1HKOI 2007 Senior Q1

Kelly ChoiKelly Choi

Page 2: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

The ProblemThe Problem

The COW Team are going to look for The COW Team are going to look for treasures in treasures in NN ruins in a rectangular map. ruins in a rectangular map.

A storage centre is to be built in one of the A storage centre is to be built in one of the regions (possibly one containing a ruin).regions (possibly one containing a ruin).

We would like to minimize the maximum of We would like to minimize the maximum of the the ManhattanManhattan distancedistance from the centre to any from the centre to any ruin.ruin. Manhattan distance from (Manhattan distance from (xx11, , yy11) to () to (xx22, , yy22))

= |= |xx11--xx22| + || + |yy11--yy22||

Page 3: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Without the story…Without the story…

Given Given NN points ( points (xxii,,yyii) with integral coordinates,) with integral coordinates, Choose a centre (Choose a centre (xx,,yy) on the coordinate plane:) on the coordinate plane:

with integral coordinates.with integral coordinates. such that max{|such that max{|xx – – xxii| + || + |yy – – yyii|} is minimized |} is minimized

among all possible centres.among all possible centres.

Page 4: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Observation 1Observation 1

The centre will not lie The centre will not lie outside the smallest outside the smallest rectangle (with sides rectangle (with sides parallel to the x and y-parallel to the x and y-axes) enclosing all the axes) enclosing all the NN points.points.

$$

$$

$$

$$

Page 5: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Algorithm 1Algorithm 1

Due to this observation, we can try every point Due to this observation, we can try every point within the rectangular region within the rectangular region RR and find out and find out the minimized maximum distance.the minimized maximum distance.

min min ←← ∞∞

For each point (For each point (xx, , yy) in ) in RR

If max {|If max {|xx--xxii| + || + |yy--yyii|} < min then|} < min then

min min ←← max {| max {|xx--xxii| + || + |yy--yyii|} |}

store x and ystore x and y

Page 6: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Algorithm 1Algorithm 1

Algorithm 1 has a time complexity of Algorithm 1 has a time complexity of O(XYN), O(XYN), where X = max{where X = max{xxii} – min{} – min{xxii}, },

Y = max{ Y = max{yyii} – min{} – min{yyii}}

It can pass 50% of the test case. But it is still It can pass 50% of the test case. But it is still too slow.too slow.

Page 7: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Let’s try another way…Let’s try another way…

Intuition suggests that we are looking for some Intuition suggests that we are looking for some kind of “centre”. But what kind of centre are kind of “centre”. But what kind of centre are we looking for?we looking for?

Page 8: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Thinking…Thinking…

IfIf direct distance instead of direct distance instead of

Manhattan distanceManhattan distance Coordinates of centre Coordinates of centre

can be decimal numberscan be decimal numbers Then…? Then…?

Page 9: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Coverage of the centreCoverage of the centre

The idea of the circular coverage in the The idea of the circular coverage in the previous case naturally leads us to think about previous case naturally leads us to think about the coverage of the storage centre, given its the coverage of the storage centre, given its maximum distancemaximum distance

Page 10: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Distance = 1Distance = 1

Page 11: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Distance = 2Distance = 2

Page 12: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Distance = 3Distance = 3

Page 13: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Distance = 4Distance = 4

Page 14: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Distance = 5Distance = 5

Page 15: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

TransformationTransformation

Now the problem can be rewritten as follows:Now the problem can be rewritten as follows: Given N selected regionsGiven N selected regions Find the smallest maximum distance such the Find the smallest maximum distance such the

coverage of the storage centre can cover all pointscoverage of the storage centre can cover all points This is equivalent to trying to fit the coverage This is equivalent to trying to fit the coverage

on the points, increasing its size whenever on the points, increasing its size whenever failed.failed.

Now, try to do it a few times by hand.Now, try to do it a few times by hand.

Page 16: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Observation 2Observation 2

After trying to fit the After trying to fit the shape on the points a shape on the points a few times, you should few times, you should realize that the task realize that the task depends on the 45depends on the 45ºº ‘lines’ instead of lines ‘lines’ instead of lines parallel to the axes.parallel to the axes.

Points lying on the same Points lying on the same 4545ºº lines have the same lines have the same ((x x + + yy) or () or (x x – – yy) values.) values.

$$

$$

$$

$$

Page 17: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Observation 2Observation 2

In the right figure, you In the right figure, you will not cover more will not cover more points if you situate the points if you situate the coverage figure beyond coverage figure beyond the black line. the black line.

$$

$$

$$

$$

Page 18: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Observation 2Observation 2

However, the black However, the black lines do not always lines do not always outline the shape of the outline the shape of the coverage.coverage.

So we have to make So we have to make decisions.decisions.

$$

$$

$$

$$

Page 19: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Case 1Case 1

The black lines exactly The black lines exactly form a shape of the form a shape of the coveragecoverage

Page 20: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Case 2Case 2

The coverage may be The coverage may be larger than the area larger than the area enclosed by the black enclosed by the black lines.lines.

Page 21: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Case 3Case 3

Things may not be that Things may not be that symmetric. symmetric.

Page 22: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Lastly, mathematicsLastly, mathematics

The black lines can be represented by its (The black lines can be represented by its (x x + + yy) or () or (x x – – yy) values.) values.

A coverage figure can be represented by A coverage figure can be represented by eithereither:: Its four edges; or Its four edges; or The centre and the sizeThe centre and the size

With the black lines, we can directly find out With the black lines, we can directly find out the four edges of the coverage figure, and thus the four edges of the coverage figure, and thus the centre.the centre.

Page 23: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

An Example of CalculationAn Example of Calculation

Black lines:Black lines: xx + + yy = 6, = 6, xx + + yy = 14 = 14 xx – – yy = -4, = -4, xx – – yy = 0 = 0

Coverage figure:Coverage figure: xx + + y = y = 66, x, x + + yy = 14 = 14 xx – – y = -y = -4, 4, xx – – yy = 4 = 4

Center:Center: SolvingSolving

xx + + y = y = (6 + 14)/2 = 10(6 + 14)/2 = 10 xx – – y = y = (-4 + 4)/2 = 0(-4 + 4)/2 = 0

Gives (Gives (xx,,yy) = (5,5)) = (5,5)

99

88

77

66

55

44

33

22

11

11 22 33 44 55 66 77 88 99

Page 24: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

CalculationsCalculations

Given the (Given the (xx + + yy) and () and (xx – – yy) values of the ) values of the black lines, we can condition on which case it black lines, we can condition on which case it is and find out the coverage figure, and then is and find out the coverage figure, and then the centre.the centre.

The ideas we have dealt with may be a bit The ideas we have dealt with may be a bit complicated, but the calculations are simple.complicated, but the calculations are simple.

Finding out the edges of the coverage figure Finding out the edges of the coverage figure first avoids the problem in directly rounding first avoids the problem in directly rounding off the values from the black lines. off the values from the black lines.

Page 25: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

CommentsComments

Interesting problemInteresting problem Requires observationRequires observation

You can improve yourself by thinking about the You can improve yourself by thinking about the problem in different approaches.problem in different approaches.

Requires some simple yet not so straight-Requires some simple yet not so straight-forward mathematicsforward mathematics

May require some ability to visualize the May require some ability to visualize the problem tooproblem too

Page 26: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Contestants’ performanceContestants’ performance

Many contestants aimed at 50% of the test Many contestants aimed at 50% of the test casescases That solution is pretty easy to arriveThat solution is pretty easy to arrive

Careless mistakes (overflow, missing Careless mistakes (overflow, missing initialization) and negligence in rounding offinitialization) and negligence in rounding off

Boundary cases: N = 1Boundary cases: N = 1 Lack of time / thinkingLack of time / thinking

Page 27: Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team

Further thinkingFurther thinking

Can the problem be done in other ways?Can the problem be done in other ways? Can the solution be modified to solve a 3D Can the solution be modified to solve a 3D

Storage Centre problem? Storage Centre problem? Can it be generalized to Can it be generalized to nn-dimensional?-dimensional? How to solve the problem when direct distance How to solve the problem when direct distance

is used instead of Manhattan distance? is used instead of Manhattan distance? What is the difference in restricting the What is the difference in restricting the

coordinates of the centre to be integers or not? coordinates of the centre to be integers or not?