1 / 8

Navigating Roads: A Statistical Quest for the Polar Bear

This problem explores the journey of a car traveling south and its interactions with roads along the way, considering polar bears as an intriguing backdrop. Given the x-coordinate position of roads and the car's trajectory, the goal is to calculate how many roads the car will visit. Observations highlight that the travel direction is limited to south, east, or west, with critical dependencies on the car's position and the roads' coordinates. The solution involves efficiently determining intersections with roads in a sorted manner, optimizing the process for swift road navigation.

ursala
Télécharger la présentation

Navigating Roads: A Statistical Quest for the Polar Bear

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. Quest for the Polar Bear Ivan Li

  2. Statistics 42 • #Max = 9 • Mean (attempted) = 39.4

  3. Problem • A car travels to the South • If it reaches a road, follow its direction • Find the number of roads visited

  4. Something you must know • The travel direction is S, E or W • Cannot go North! • There are polar bears in the South • In zoos =]

  5. Observations • Whether a car will reach a road on the south depends on the x coordinates of the car and the start and end points of the road • (x1 ≤ x and x ≤ x2) or (x2 ≤ x and x ≤ x1) • (x1-x)*(x2-x) ≤ 0 • Cool but risky =] • After the car finishes travelling on a road, its position is in the end point

  6. Be Naive • For each road, check if the car will hit it if the car go straight • Road on the south of the car? • Check x coordinates? • If it will, calculate the time (difference in y coordinates) the car will hit the road • Then go hit the road with min time! • Repeat the process until the car hit no roads • O(n2)

  7. Important Observations • After the car has passed a road • i.e. y coordinates of car smaller than road • Then we can ignore the road sayonara!!! • When the car has y coordinate equals that of a road • Hit or miss • Hit: change the position of the car, bye to the road • Miss: Just bye to the road • The y coordinates of the car won’t increase • The car must visit the roads in y order • The input is sorted!

  8. Full Solution • Keep the index of the last road not passed • Hit or Miss? • Increment the index • Complexity O(n)

More Related