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.

Slides:



Advertisements
Similar presentations
MA 1128: Lecture 06 – 2/15/11 Graphs Functions.
Advertisements

CSE 781 Anti-aliasing for Texture Mapping. Quality considerations So far we just mapped one point – results in bad aliasing (resampling problems) We really.
Roundoff and truncation errors
An Improved Algorithm for the Rectangle Enclosure Problem Anatoli Uchitel From an article By D.T. Lee and F.P. Preparata (March 8, 1981)
Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
Approximations of points and polygonal chains
Exponential Functions Logarithmic Functions
Applications of Integration 6. Volumes Volumes In trying to find the volume of a solid we face the same type of problem as in finding areas. We.
APPLICATIONS OF INTEGRATION
§ 8.3 Quadratic Functions and Their Graphs.
§ 8.3 Quadratic Functions and Their Graphs. Graphing Quadratic Functions Blitzer, Intermediate Algebra, 5e – Slide #2 Section 8.3 The graph of any quadratic.
Atlantis HKOI2005 Final Event (Senior Group). 2 Background 9000 B.C B.C. Atlantis Zeus Other gods Destroy!!
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
10 Applications of Definite Integrals Case Study
Closest Pair Given a set S = {p1, p2,..., pn} of n points in the plane find the two points of S whose distance is the smallest. Images in this presentation.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 18 Sit in your groups.
15 PARTIAL DERIVATIVES.
Principal Component Analysis CMPUT 466/551 Nilanjan Ray.
CPSC 668Set 5: Synchronous LE in Rings1 CPSC 668 Distributed Algorithms and Systems Spring 2008 Prof. Jennifer Welch.
Computing Diameter in the Streaming and Sliding-Window Models J. Feigenbaum, S. Kannan, J. Zhang.
Prune-and-search Strategy
15 PARTIAL DERIVATIVES.
16 MULTIPLE INTEGRALS.
MULTIPLE INTEGRALS Double Integrals over General Regions MULTIPLE INTEGRALS In this section, we will learn: How to use double integrals to.
Gradient Methods Yaron Lipman May Preview Background Steepest Descent Conjugate Gradient.
Systems of Inequalities Created By Richard Gill and Jeannie Taylor For Mth 163: Precalculus 1 Funded by a Grant from the VCCS LearningWare Program.
Copyright © Cengage Learning. All rights reserved.
Isometric projection Projection on a plane such that mutually perpendicular edges appear at 120o to each other. Iso (same) angle between the axes. Example.
Domain decomposition in parallel computing Ashok Srinivasan Florida State University COT 5410 – Spring 2004.
Multiple Integration 14 Copyright © Cengage Learning. All rights reserved.
Multiple Integrals 12. Double Integrals over General Regions 12.3.
Copyright © Cengage Learning. All rights reserved Double Integrals over General Regions.
DOUBLE INTEGRALS OVER GENERAL REGIONS
October 14, 2014Computer Vision Lecture 11: Image Segmentation I 1Contours How should we represent contours? A good contour representation should meet.
Engineering Mechanics: Statics
© The McGraw-Hill Companies, Inc., Chapter 6 Prune-and-Search Strategy.
Introduction to Computational Geometry Hackson
ACT MATH TEST You are given 60 minutes to answer 60 questions. That’s 60 seconds or less per question. You should memorize the instructions for the Math.
College Algebra Fifth Edition James Stewart Lothar Redlin Saleem Watson.
Copyright © Cengage Learning. All rights reserved. Polar Coordinates and Parametric Equations.
1 Prune-and-Search Method 2012/10/30. A simple example: Binary search sorted sequence : (search 9) step 1  step 2  step 3  Binary search.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
Numerical Methods.
Area of Complex Figures. What are complex figures? Figures that can be subdivided into simple figures.
Tangents and Normals We’re going to talk about tangents and normals to 3-D surfaces such as x 2 + y 2 + z 2 = 4 It’s useful to think of these surfaces.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 5: Synchronous LE in Rings 1.
Introduction: what do we want to get out of chapter 24?
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
SECTION 12.5 TRIPLE INTEGRALS.
Copyright © Cengage Learning. All rights reserved.
Extreme Values Let f (x,y) be defined on a region R containing P(x 0,y 0 ): P is a relative max of f if f (x,y) ≤ f (x 0,y 0 ) for all (x,y) on an open.
Definite Integration and Areas 01 It can be used to find an area bounded, in part, by a curve e.g. gives the area shaded on the graph The limits of integration...
Section 1-1 Points and Lines. Each point in the plane can be associated with an ordered pair of numbers, called the coordinates of the point. Each ordered.
Common Intersection of Half-Planes in R 2 2 PROBLEM (Common Intersection of half- planes in R 2 ) Given n half-planes H 1, H 2,..., H n in R 2 compute.
Functions 2 Copyright © Cengage Learning. All rights reserved.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
TRIGONOMETRY – Functions 1 We will now place the angle in the x–y plane. The initial side of the angle will always be placed on the (+) side of the x –
Copyright © Cengage Learning. All rights reserved. 5.2 Volumes
Trigonometric Functions of Real Numbers 5. Trigonometric Graphs 5.3.
COORDINATE SYSTEMS & TRANSFORMATION
Generating Random Variates
Copyright © Cengage Learning. All rights reserved. 4 Integrals.
Grouping and Segmentation. Sometimes edge detectors find the boundary pretty well.
P2 Chapter 8 CIE Centre A-level Pure Maths © Adam Gibson.
Software Testing.
Software Testing (Lecture 11-a)
Create a design (image) on the graph paper on the last page, making sure at least 3 vertices land on whole number (integer) coordinates, in the upper left.
Presentation transcript:

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

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.

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

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

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.

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?

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…?

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

Distance = 1

Distance = 2

Distance = 3

Distance = 4

Distance = 5

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.

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

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

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

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

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.

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

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.

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)

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.

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

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

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?