Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Storage Centre HKOI 2007 Senior Q1 Kelly Choi

2 The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team are going to look for treasures in N ruins in a rectangular map. A storage centre is to be built in one of the regions (possibly one containing a ruin). A storage centre is to be built in one of the regions (possibly one containing a ruin). We would like to minimize the maximum of the Manhattan distance from the centre to any ruin. We would like to minimize the maximum of the Manhattan distance from the centre to any ruin. Manhattan distance from (x 1, y 1 ) to (x 2, y 2 ) = |x 1 -x 2 | + |y 1 -y 2 | Manhattan distance from (x 1, y 1 ) to (x 2, y 2 ) = |x 1 -x 2 | + |y 1 -y 2 |

3 Without the story… Given N points (x i,y i ) with integral coordinates, Given N points (x i,y i ) with integral coordinates, Choose a centre (x,y) on the coordinate plane: Choose a centre (x,y) on the coordinate plane: with integral coordinates. with integral coordinates. such that max{|x – x i | + |y – y i |} is minimized among all possible centres. such that max{|x – x i | + |y – y i |} is minimized among all possible centres.

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

5 Algorithm 1 Due to this observation, we can try every point within the rectangular region R and find out the minimized maximum distance. Due to this observation, we can try every point within the rectangular region R and find out the minimized maximum distance. min ← ∞ For each point (x, y) in R If max {|x-x i | + |y-y i |} < min then min ← max {|x-x i | + |y-y i |} store x and y

6 Algorithm 1 Algorithm 1 has a time complexity of O(XYN), Algorithm 1 has a time complexity of O(XYN), where X = max{x i } – min{x i }, Y = max{y i } – min{y i } where X = max{x i } – min{x i }, Y = max{y i } – min{y i } It can pass 50% of the test case. But it is still too slow. It can pass 50% of the test case. But it is still too slow.

7 Let’s try another way… Intuition suggests that we are looking for some kind of “centre”. But what kind of centre are we looking for? Intuition suggests that we are looking for some kind of “centre”. But what kind of centre are we looking for?

8 Thinking… If If direct distance instead of Manhattan distance direct distance instead of Manhattan distance Coordinates of centre can be decimal numbers Coordinates of centre can be decimal numbers Then…? Then…?

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

10 Distance = 1

11 Distance = 2

12 Distance = 3

13 Distance = 4

14 Distance = 5

15 Transformation Now the problem can be rewritten as follows: Now the problem can be rewritten as follows: Given N selected regions Given N selected regions Find the smallest maximum distance such the coverage of the storage centre can cover all points Find the smallest maximum distance such the coverage of the storage centre can cover all points This is equivalent to trying to fit the coverage on the points, increasing its size whenever failed. This is equivalent to trying to fit the coverage on the points, increasing its size whenever failed. Now, try to do it a few times by hand. Now, try to do it a few times by hand.

16 Observation 2 After trying to fit the shape on the points a few times, you should realize that the task depends on the 45º ‘lines’ instead of lines parallel to the axes. After trying to fit the shape on the points a few times, you should realize that the task depends on the 45º ‘lines’ instead of lines parallel to the axes. Points lying on the same 45º lines have the same (x + y) or (x – y) values. Points lying on the same 45º lines have the same (x + y) or (x – y) values. $ $ $ $

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

18 Observation 2 However, the black lines do not always outline the shape of the coverage. However, the black lines do not always outline the shape of the coverage. So we have to make decisions. So we have to make decisions. $ $ $ $

19 Case 1 The black lines exactly form a shape of the coverage The black lines exactly form a shape of the coverage

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

21 Case 3 Things may not be that symmetric. Things may not be that symmetric.

22 Lastly, mathematics The black lines can be represented by its (x + y) or (x – y) values. The black lines can be represented by its (x + y) or (x – y) values. A coverage figure can be represented by either: A coverage figure can be represented by either: Its four edges; or Its four edges; or The centre and the size The centre and the size With the black lines, we can directly find out the four edges of the coverage figure, and thus the centre. With the black lines, we can directly find out the four edges of the coverage figure, and thus the centre.

23 An Example of Calculation Black lines: Black lines: x + y = 6, x + y = 14 x + y = 6, x + y = 14 x – y = -4, x – y = 0 x – y = -4, x – y = 0 Coverage figure: Coverage figure: x + y = 6, x + y = 14 x + y = 6, x + y = 14 x – y = -4, x – y = 4 x – y = -4, x – y = 4 Center: Center: Solving Solving x + y = (6 + 14)/2 = 10 x + y = (6 + 14)/2 = 10 x – y = (-4 + 4)/2 = 0 x – y = (-4 + 4)/2 = 0 Gives (x,y) = (5,5) Gives (x,y) = (5,5) 9 8 7 6 5 4 3 2 1 123456789

24 Calculations Given the (x + y) and (x – y) values of the black lines, we can condition on which case it is and find out the coverage figure, and then the centre. Given the (x + y) and (x – y) values of the black lines, we can condition on which case it is and find out the coverage figure, and then the centre. The ideas we have dealt with may be a bit complicated, but the calculations are simple. The ideas we have dealt with may be a bit complicated, but the calculations are simple. Finding out the edges of the coverage figure first avoids the problem in directly rounding off the values from the black lines. Finding out the edges of the coverage figure first avoids the problem in directly rounding off the values from the black lines.

25 Comments Interesting problem Interesting problem Requires observation Requires observation You can improve yourself by thinking about the problem in different approaches. You can improve yourself by thinking about the problem in different approaches. Requires some simple yet not so straight- forward mathematics Requires some simple yet not so straight- forward mathematics May require some ability to visualize the problem too May require some ability to visualize the problem too

26 Contestants’ performance Many contestants aimed at 50% of the test cases Many contestants aimed at 50% of the test cases That solution is pretty easy to arrive That solution is pretty easy to arrive Careless mistakes (overflow, missing initialization) and negligence in rounding off Careless mistakes (overflow, missing initialization) and negligence in rounding off Boundary cases: N = 1 Boundary cases: N = 1 Lack of time / thinking Lack of time / thinking

27 Further 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 Storage Centre problem? Can the solution be modified to solve a 3D Storage Centre problem? Can it be generalized to n-dimensional? Can it be generalized to n-dimensional? How to solve the problem when direct distance is used instead of Manhattan distance? How to solve the problem when direct distance is used instead of Manhattan distance? What is the difference in restricting the coordinates of the centre to be integers or not? What is the difference in restricting the coordinates of the centre to be integers or not?


Download ppt "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."

Similar presentations


Ads by Google