1 / 27

Storage Centre

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. A storage centre is to be built in one of the regions (possibly one containing a ruin).

eddy
Download Presentation

Storage Centre

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. 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. • 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 Manhattandistance from the centre to any ruin. • Manhattan distance from (x1, y1) to (x2, y2)= |x1-x2| + |y1-y2|

  3. Without the story… • Given N points (xi,yi) with integral coordinates, • Choose a centre (x,y) on the coordinate plane: • with integral coordinates. • such that max{|x – xi| + |y – yi|} 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.

  5. Algorithm 1 • 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-xi| + |y-yi|} < min then min ← max {|x-xi| + |y-yi|} store x and y

  6. Algorithm 1 • Algorithm 1 has a time complexity of O(XYN), • where X = max{xi} – min{xi}, Y = max{yi} – min{yi} • 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?

  8. Thinking… • If • direct distance instead of Manhattan distance • Coordinates of centre can be decimal numbers • 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

  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: • Given N selected regions • 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. • 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. • 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.

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

  19. Case 1 • 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.

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

  22. Lastly, mathematics • The black lines can be represented by its (x + y) or (x – y) values. • A coverage figure can be represented by either: • Its four edges; or • 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.

  23. An Example of Calculation • Black lines: • x + y = 6, x + y = 14 • x – y = -4, x – y = 0 • Coverage figure: • x + y = 6, x + y = 14 • x – y = -4, x – y = 4 • Center: • Solving • x + y = (6 + 14)/2 = 10 • x – y = (-4 + 4)/2 = 0 • Gives (x,y) = (5,5)

  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. • 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.

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

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

  27. Further thinking • Can the problem be done in other ways? • Can the solution be modified to solve a 3D Storage Centre problem? • Can it be generalized to n-dimensional? • 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?

More Related