BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle



Similar documents
5.3 The Cross Product in R 3

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

The Dot and Cross Products

12.5 Equations of Lines and Planes

L 2 : x = s + 1, y = s, z = 4s Suppose that C has coordinates (x, y, z). Then from the vector equality AC = BD, one has

THREE DIMENSIONAL GEOMETRY

One advantage of this algebraic approach is that we can write down

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Co-ordinate Geometry THE EQUATION OF STRAIGHT LINES

Selected practice exam solutions (part 5, item 2) (MAT 360)

DEFINITIONS. Perpendicular Two lines are called perpendicular if they form a right angle.

Figure 1.1 Vector A and Vector F

Problem set on Cross Product

Lecture 14: Section 3.3

Solutions to old Exam 1 problems

MAT 1341: REVIEW II SANGHOON BAEK

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

= y y 0. = z z 0. (a) Find a parametric vector equation for L. (b) Find parametric (scalar) equations for L.

v 1 v 3 u v = (( 1)4 (3)2, [1(4) ( 2)2], 1(3) ( 2)( 1)) = ( 10, 8, 1) (d) u (v w) = (u w)v (u v)w (Relationship between dot and cross product)

LINES AND PLANES IN R 3

Section 13.5 Equations of Lines and Planes

4. How many integers between 2004 and 4002 are perfect squares?

Review Sheet for Test 1

Section 9.5: Equations of Lines and Planes

Geometry Module 4 Unit 2 Practice Exam

CHAPTER FIVE. 5. Equations of Lines in R 3

13.4 THE CROSS PRODUCT

Equations Involving Lines and Planes Standard equations for lines in space

1 Solution of Homework

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.


Section 1.4. Lines, Planes, and Hyperplanes. The Calculus of Functions of Several Variables

Math 241, Exam 1 Information.

Terminology: When one line intersects each of two given lines, we call that line a transversal.

Solving Linear Systems, Continued and The Inverse of a Matrix

Most popular response to

Lesson 5-3: Concurrent Lines, Medians and Altitudes

Section 1.1. Introduction to R n

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

Lecture 24: Saccheri Quadrilaterals

Unified Lecture # 4 Vectors

FURTHER VECTORS (MEI)

3. INNER PRODUCT SPACES

Geometric description of the cross product of the vectors u and v. The cross product of two vectors is a vector! u x v is perpendicular to u and v

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

Chapter 18 Symmetry. Symmetry of Shapes in a Plane then unfold

Example SECTION X-AXIS - the horizontal number line. Y-AXIS - the vertical number line ORIGIN - the point where the x-axis and y-axis cross

CSU Fresno Problem Solving Session. Geometry, 17 March 2012


Section 2.4: Equations of Lines and Planes

39 Symmetry of Plane Figures

Mechanics lecture 7 Moment of a force, torque, equilibrium of a body

SAT Subject Math Level 1 Facts & Formulas

Parallel and Perpendicular. We show a small box in one of the angles to show that the lines are perpendicular.

Section 9.1 Vectors in Two Dimensions

discuss how to describe points, lines and planes in 3 space.

11.3 Curves, Polygons and Symmetry

Determine whether the following lines intersect, are parallel, or skew. L 1 : x = 6t y = 1 + 9t z = 3t. x = 1 + 2s y = 4 3s z = s

Solutions to Practice Problems

Lecture L3 - Vectors, Matrices and Coordinate Transformations

Shortest Path Algorithms

Orthogonal Projections

1. A student followed the given steps below to complete a construction. Which type of construction is best represented by the steps given above?

GeoGebra. 10 lessons. Gerrit Stols

Solving Systems of Linear Equations

C relative to O being abc,, respectively, then b a c.

Trigonometric Functions: The Unit Circle

Contents. 2 Lines and Circles Cartesian Coordinates Distance and Midpoint Formulas Lines Circles...

Lecture 8 : Coordinate Geometry. The coordinate plane The points on a line can be referenced if we choose an origin and a unit of 20

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

MATHEMATICS Y6 Geometry 6750 Use co-ordinates and extend to 4 quadrants Equipment MathSphere

37 Basic Geometric Shapes and Figures

Høgskolen i Narvik Sivilingeniørutdanningen STE6237 ELEMENTMETODER. Oppgaver

n 2 + 4n + 3. The answer in decimal form (for the Blitz): 0, 75. Solution. (n + 1)(n + 3) = n lim m 2 1

SAT Subject Math Level 2 Facts & Formulas

Solving Simultaneous Equations and Matrices

Geometry Review Flash Cards

Section The given line has equations. x = 3 + t(13 3) = t, y = 2 + t(3 + 2) = 2 + 5t, z = 7 + t( 8 7) = 7 15t.

Vector Algebra II: Scalar and Vector Products

Biggar High School Mathematics Department. National 5 Learning Intentions & Success Criteria: Assessing My Progress

Vector Math Computer Graphics Scott D. Anderson

Definitions, Postulates and Theorems

Name Class. Date Section. Test Form A Chapter 11. Chapter 11 Test Bank 155

9 Multiplication of Vectors: The Scalar or Dot Product

6. Vectors Scott Surgent (surgent@asu.edu)

Situation: Proving Quadrilaterals in the Coordinate Plane

Chapter 3.1 Angles. Geometry. Objectives: Define what an angle is. Define the parts of an angle.

MODERN APPLICATIONS OF PYTHAGORAS S THEOREM

1 VECTOR SPACES AND SUBSPACES

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Math 215 HW #6 Solutions

Geometry 8-1 Angles of Polygons

The Triangle and its Properties

MATH 304 Linear Algebra Lecture 20: Inner product spaces. Orthogonal sets.

1.5 Equations of Lines and Planes in 3-D

Numerical Analysis Lecture Notes

Two vectors are equal if they have the same length and direction. They do not

Transcription:

Page 1 of?? ENG rectangle Rectangle Spoiler Solution of SQUARE For start, let s solve a similar looking easier task: find the area of the largest square. All we have to do is pick two points A and B and find the coordinates of two other points in such a way that all four points form a square. There are two valid pairs of points on one side of the line AB and on the other. For each of the pairs, we check whether both points actually exist. This check can be done in either O(log n) (if we store the points in a tree or use binary search) or O(1) (if we hash each given point initially). We have to check every pair of points, hence the total complexity is O(n 2 ). Solution of RECTANGLE First, we notice that rectangles (and only rectangles!) have the following property: all four distances from the point of intersection of their diagonals to each vertex are equal. For each pair of points (let s denote these points by A and B) we store a record R containing the following values: R.x = (A x + B x )/2 R.y = (A y + B y )/2 R.d = (A x B x ) 2 + (A y B y ) 2 R.α the angle between x axis and the segment AB Note that (R.x,R.y) is the midpoint of the segment AB. We will see later that it is not in fact necessary to divide A + B and A + B by two.

Page 2 of?? ENG rectangle We sort these n(n 1) 2 records by (x,y), then by d and then by α value. Suppose we have two records, R 1 and R 2, with R 1.x = R 2.x, R 1.y = R 2.y and R 1.d = R 2.d. According to what was said before, this means that four points which produced these two records form a rectangle. Moreover, its area is equal to 2 1 d d sin α = 1 2dsin α. When the records are sorted, we can process each set of records having equal x, y and d values separately. Illustration of one such set would look like this: We have to choose two of these segments in such a way that the rectangle would have the largest possible area. As d is fixed, we have to maximize sin α. In other words, we want the angle between two chosen segments to be as close as possible to 90 degrees. This can be achieved using two cursors. Let s say the segments are numbered from 1 to M anticlockwise, as can be seen in the drawing (in our case M = 10). At first, both cursors point to the first segment. Now, while the current angle is less than 90 degrees, we increase the second cursor. After some time, the angle becomes more or equal than 90 degrees. This is the time when we start moving the first cursor we move it forward until the angle becomes less or equal than 90 degrees. Then we move the second cursor etc. We finish when the first cursor points to the segment whose y coordinate is less than zero (the segment number 6 in our case). This last part can also be done by simply checking every pair or segments it will work slower but still not exceed the time limit. As we have to sort O(n 2 ) records, the total time complexity is O(n 2 log n). A final note: of course, it is not necessary to store the exact value of the angles if we want to avoid dealing with real numbers. We just need to know two things: 1. which of two angles is larger; 2. whether the difference between two angles is smaller or larger than 90 degrees. Inefficient solution The O(n 3 ) solution is based on the solution of square problem. We consider every three of the given points and do the following:

Page 3 of?? ENG rectangle 1. Check whether they form a right triangle; 2. If they do, we calculate what the coordinates of the fourth vertex would be (in order for all four vertices to form a rectangle); 3. Check if there exists a given point at these coordinates. Each of these steps takes O(1) time. Alternative solution Below is a short description of a similar approach which yields better performance. We try to solve the following task: find the number of right triangles whose vertices are from the given set of points. This task was used in Croatian COCI 2007 Olympiad. Using cursor approach, this task can be solved in O(n 2 log n) time. However, for every right triangle we find we have to check for the fourth vertex (as we did in Inefficient solution). Thus, the total complexity would be O(n 2 log n + t) where t is the number of right triangles. In practice, t n 2 log n for n 1,500 and therefore this solution is good enough to receive full score. See: http://www.hsin.hr/coci/archive/2007_2008/contest2_tasks.pdf Yet another solution sorting vectors Let us consider a rectangle on the plane and pick its vertex having minimum y coordinate (if two vertices have the same y coordinate, we pick the leftmost vertex). Let s denote this vertex by A. It is easy to see that vertex A is connected to a neighboring vertex B such that B x A x 0 and B y A y > 0. In other words, for vector AB = (vx,v y ) we have v x 0 and v y > 0. Also note that the vector formed by other two vertices, DC, is equal to AB. C D (v x,v y ) B A (v x,v y ) Now, let s check every pair of the given points and collect vectors which have this property (v x 0 and v y > 0). We can sort these vectors so that we can process the sets of equal vectors easily. Let s consider one such set of equal vectors and assume these vectors are (v x,v y ). Any two vectors of the set form a parallelogram. Let s figure out when they form a rectangle. For this purpose, let s pick two vectors and assume the coordinates of their origins are (x 1,y 1 ) and (x 2,y 2 ). Sure enough,

Page 4 of?? ENG rectangle to form a rectangle, the vectors (v x,v y ) and (x 2 x 1,y 2 y 1 ) have to be perpendicular, which means that their scalar product has to be zero: (x 2 x 1 )v x + (y 2 y 1 )v y = 0. In other words, x 1 v x + y 1 v y = x 2 v x + y 2 v y. So we come to the following conclusion: two equal vectors form a rectangle if and only if their v-values are equal where the v-value of a vector (v x,v y ) with the origin at (x 1,y 1 ) is defined as x 1 v x + y 1 v y. (x 2,y 2 ) (v x,v y ) (x 1,y 1 ) Now, we can either check all rectangles and choose the largest one or we can make an optimization based on the following observation. First, we note that all equal vectors can be further divided into groups of vectors having the same v-value. Let s consider one such group. Of course, any two vectors of this group form a rectangle. In fact, origins of these vectors are located on a line which is perpendicular to the vectors. Therefore the largest rectangle is obtained from two vectors with their origins lying on extreme ends of this line. We can find these extreme vectors by simply taking a vector which has the minimum x coordinate of its origin and a vector which has the maximum x coordinate of its origin. Note that this line where the origin points lie cannot be vertical because at the very beginning we chose the vectors with v y > 0. In this solution, we must sort O(n 2 ) vectors, therefore the total complexity is O(n 2 log n).

Page 5 of?? ENG rectangle Test data overview # n Triangles Rectangles Answer Optimal MaxCoord Remarks Points 0 8 22 3 10 1 3 Square 0 1 11 33 4 588 1 72 1 2 25 136 3 1223068 1 4806 Orthogonal 1 3 55 313 1 2071510376 1 786713 Square 1 4 102 192 23 786080 1 6013 2 5 199 48687 7349 1537360689312250 2 96803808 Square 2 6 309 74883 6458 139656460 1 9688 Orthogonal 2 7 353 1980 435 6967659886146 1 99811664 2 8 404 59376 6297 1615667124561765 1 93505480 3 9 448 9449 1 343200 1 6276 3 10 500 51042 10895 296329760 1 100000000 3 11 636 30092 271 1140700 1 9103 3 12 707 930325 154583 1865324372100 1 1465826 3 13 805 3613 112 1223032004876 1 2214859 4 14 902 3448 1 70301 1 8197 Orthogonal 4 15 1006 33132 528 19542192522058220 1 99547443 5 16 1103 22258 1549 4108806711522 4 1983220 Orthogonal 6 17 1191 22910 2761 199338750 1 10000 7 18 1325 125905 638 53801600 1 9408 8 19 1404 1014171 33590 3853519190576640 1 97381415 10 20 1488 2469480 339472 892144747132240 1 99994017 10 21 1500 3117 88 2053316907252 1 51198452 10 22 1500 5381228 1023027 5883783690585240 1 79730583 10 Legend: n the number of points. Triangles the number of right triangles with vertices in the given points. Rectangles the number of rectangles with vertices in the given points. Answer the area of the largest rectangle. Optimal the number of rectangles which have the maximum area. MaxCoord the maximum absolute value of coordinates of the points. Remarks: Square the largest rectangle is a square. Remarks: Orthogonal the sides of the largest rectangle are parallel to coordinate axes.