1 / 12

Little Stage

Optimize the construction of an H-shaped stage that covers all hot spots in a zoo while minimizing its area, using integral coordinates and considering symmetry. Explore different solutions and their mathematical expressions.

nhargrove
Download Presentation

Little Stage

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. Little Stage HKOI 2007 Junior Q2

  2. The Problem • Given N hot spots in the zoo, build a H-shaped stage that covers all hot spots, with its area minimized. • Integral coordinates • The H-shaped stage: • Composed of one-unit wide three blocks, each parallel to the boundary of the zoo • Symmetric in shape

  3. How can the stage be built? • Does a “|” satisfy the requirement? • Does an “I” satisfy the requirement? • Is the coordinate plane bounded?

  4. When is it possible? • Can we always build an H-shaped stage? • Obviously not, since the width of each block is restricted to 1. • When can we build an H-shaped stage? • Can we express this in mathematical terms?

  5. If it is possible • Will an “H” and an “I” be both possible? • To calculate its area, we can find out the blocks first. • How to find out the blocks?

  6. Naïve Solution • For each x coordinate xl as the left block • For each x coordinate xr as the right block, xl<xr • For each y coordinate as the middle block • Check if all points lie on them • If yes, find out the minimum possible length of the left and right block, and then the area • Do the same for the other direction • O(X2YN + XY2N) • Note the possible range of x, y

  7. Optimization • In the third for-loop, how many y values will we succeed with? • One only, or zero • Can we find out that y value more efficiently? • Yes • For that y value, all the N points either lie on the left and right block, or between the left and right block and on that y coordinate • What if all points lie on the left and right block?

  8. Second attempt • For each x coordinate xl as the left block • For each x coordinate xr as the right block, xl<xr • Check if all points that do not lie on the left or right block have the same y coordinate • If yes, take that y coordinate for the middle block, find out the minimum possible length of the left and right block, and then the area • Do the same for the other direction • O(X2N + Y2N)

  9. Optimization again • How about the first two for-loops? • Actually, there are only one possible case. • There must be no points on the left of the left block, nor on the right of the right block. • So xl = min {xi} and xr = max {xi}

  10. Final attempt • Take min {xi} as the left block • Take max {xi} as the left block • Check if all points that do not lie on the left or right block have the same y coordinate • If yes, take that y coordinate for the middle block, find out the minimum possible length of the left and right block, and then the area • Do the same for the other direction • O(N)

  11. Implementation • Be careful with: • Cases where it is impossible to build the stage • Boundary cases and special cases

  12. What have we learnt? • Observations can help to make your program faster • Try to think of: • What is unnecessary • Other ways to do the same thing, more efficiently

More Related