Manhattan skyline def manhattan_skyline(towers): This classic problem in computational geometry (essentially, geometry that can be done using only integer arithmetic; yes, that is an actual thing) is best illustrated by pictures and animations such as those on the page "The Skyline problem", so you can first check that it out to get an idea of what is going on. Given a list of rectangular towers as tuples (s, e, h) where s and e are the start and end x-coordinates (satisfying e>s) and h is the height of that tower, compute and return the total visible area of the towers, being careful not to double count two or more towers that are partially overlapping. All towers share the same flat ground baseline at the height.   The classic solution illustrates the important sweep line technique that starts by creating a list of precisely those x-coordinate values where something relevant to the problem takes place. In this problem, the relevant x-coordinates are those where some tower either starts or ends. Next, loop through this list in ascending order, updating your computation for the interval between the current relevant x-coordinate and the previous one. In this particular problem, you need to maintain a list of active towers so that tower (s, e, h) becomes active when x==s, and becomes inactive again when x==e. Inside each interval, only the tallest active tower affects the area summation.   The automated tester script will produce start and end coordinates from an increasing scale to prevent this problem being solved with the inferior method that builds up the list of all positions from zero up to the maximum end coordinate in towers, loops through the towers to update the tallest tower height at each position, and sums up these heights for the final area.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Manhattan skyline

def manhattan_skyline(towers):
This classic problem in computational geometry (essentially, geometry that can be done using only integer arithmetic; yes, that is an actual thing) is best illustrated by pictures and animations such as those on the page "The Skyline problem", so you can first check that it out to get an idea of what is
going on. Given a list of rectangular towers as tuples (s, e, h) where s and e are the start and end x-coordinates (satisfying e>s) and h is the height of that tower, compute and return the total visible area of the towers, being careful not to double count two or more towers that are partially
overlapping. All towers share the same flat ground baseline at the height.

 

The classic solution illustrates the important sweep line technique that starts by creating a list of precisely those x-coordinate values where something relevant to the problem takes place. In this problem, the relevant x-coordinates are those where some tower either starts or ends. Next, loop through this list in ascending order, updating your computation for the interval between the current relevant x-coordinate and the previous one. In this particular problem, you need to maintain a list of active towers so that tower (s, e, h) becomes active when x==s, and becomes inactive
again when x==e. Inside each interval, only the tallest active tower affects the area summation.

 

The automated tester script will produce start and end coordinates from an increasing scale to prevent this problem being solved with the inferior method that builds up the list of all positions from zero up to the maximum end coordinate in towers, loops through the towers to update the tallest tower height at each position, and sums up these heights for the final area.

towers
Expected result
[ (2, 3, 39)]
39
[ (6, 8, 56), (5, 14, 81), (3, 13, 71)]
871
[ (6,
93)]
18, 95), (3, 20, 95), (14, 31, 22), (5, 12, 1857
[(16, 88, 20), (11, 75, 22), (43, 73, 27), (21,
42, 37), (20, 89, 12), (67, 68, 19), (1, 65,
24), (78, 91, 34), (65, 117, 9)]
2871
Transcribed Image Text:towers Expected result [ (2, 3, 39)] 39 [ (6, 8, 56), (5, 14, 81), (3, 13, 71)] 871 [ (6, 93)] 18, 95), (3, 20, 95), (14, 31, 22), (5, 12, 1857 [(16, 88, 20), (11, 75, 22), (43, 73, 27), (21, 42, 37), (20, 89, 12), (67, 68, 19), (1, 65, 24), (78, 91, 34), (65, 117, 9)] 2871
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education