subject

The streets of a certain city form a very regular square grid. Some streets run north-south and others run east-west. Every intersection can be described by a pair of integer coordinates (i, j) in an obvious way. Because of the grid geometry, the distance you have to walk to get from one intersection (i1,j1) to another intersection (i2, j2) is |i1 − i2| + |j1 − j2|. For simplicity let us assume that the address of each resident of the city is some intersection point (i, j). The city wants to locate a hospital at some intersection in such a way as to minimize the total distance traveled by all residents to get to the hospital. Your task is to design an algorithm that takes as input a list of addresses (repeats allowed) of all n residents in the city , and return the location of the hospital that is optimal with respect to the city’s criterion above. Design such an algorithm that runs in O(n) time.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 05:20
Write a program called assignment3 (saved in a file assignment3.java) that computes the greatest common divisor of two given integers. one of the oldest numerical algorithms was described by the greek mathematician, euclid, in 300 b.c. it is a simple but very e↵ective algorithm that computes the greatest common divisor of two given integers. for instance, given integers 24 and 18, the greatest common divisor is 6, because 6 is the largest integer that divides evenly into both 24 and 18. we will denote the greatest common divisor of x and y as gcd(x, y). the algorithm is based on the clever idea that the gcd(x, y) = gcd(x ! y, y) if x > = y and gcd(x, y) = gcd(x, y ! x) if x < y. the algorithm consists of a series of steps (loop iterations) where the “larger” integer is replaced by the di↵erence of the larger and smaller integer. this continues until the two values are equal. that is then the gcd.
Answers: 3
question
Computers and Technology, 22.06.2019 15:10
Which activity should be part of a long-term plan to positively affect yourhealth? oa. wearing regular clothing when handling toxinsob. not worrying about secondhand smokeoc. avoiding excessive exposure to sunlightod. drinking only well water
Answers: 1
question
Computers and Technology, 22.06.2019 21:00
Ulia is planning to attend the same private four-year college her parents attended. she wants to save at least $18,000 in four years to contribute to her college education. which monthly deposit amounts can julia use to achieve her goal? check all that apply.
Answers: 2
question
Computers and Technology, 22.06.2019 22:30
The qwerty keyboard is the most common layout of keys on a keyboard
Answers: 3
You know the right answer?
The streets of a certain city form a very regular square grid. Some streets run north-south and othe...
Questions
Questions on the website: 13722361