A number of cities are arranged on a graph that has been divided up like an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A number of cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) coordinate intersection. City names and locations are given in the form of three arrays: c, x, and y, which are aligned by the index to provide the city name (c[i]), and its coordinates, (x[i], y[i]). Determine the name of the nearest city that shares either an x or a y coordinate with the queried city. If no other cities share an x or y coordinate, return 'NONE'. If two cities have the same distance to the queried city, q[i], consider the one with an alphabetically shorter name (i.e. 'ab' < 'aba'<'abb) as the closest choice. The distance is the Manhattan distance, the absolute difference in x plus the absolute difference in y. 5 4 C3 H 3 2 C2 1. 1 2 3 X y Example n = 3 c = ['c1', 'c2', 'c3'] x = [3, 2, 1] y = [3, 2, 3] q=['c1', 'c2', 'c3'] C1 4 5 The three points at (x[i], y[i]) are (3, 3), (2, 2) and (1, 3) represent the coordinates of the cities on the graph. The nearest city to c1 is c3, which shares a y value (distance = (3-1) + (3-3) = 2). City c2 does not have a nearest city as none share an xor y with c2, so this query returns 'NONE'. A query of c3 returns c1 based on the first calculation. The return array after all queries are complete is ['c3', 'NONE', 17. Function Description Complete the function closestStraightCity in the editor below. 1 > #!/bin/python3... 10 11 # 12 # Complete the closestStraightCity' function below. 13 14 15 16 17 18 19 20 21 22 23 # # The function is expected to return a STRING_ARRAY. # The function accepts following parameters: # 1. STRING ARRAY C # 2. INTEGER_ARRAY X # 3. INTEGER ARRAY y # 4. STRING_ARRAY q # def closestStraightCity (c, x, y, q): # Write your code here 24 25 > if __name__ == '__main__' Activate Windows Go to Settings to activate Windows. Function Description Complete the function closestStraightCity in the editor below. closestStraightCity has the following parameter(s): string c[n]: an array of strings that represent the names of each city[i] int x[n]: the x coordinates of each city[i] int y[n]: the y coordinates of each city[i] string q[m]: the names of each city to query Returns: string[m]: an array of m strings where the index of i element denotes the return value of the index of i query Constraints 1 ≤n, m≤ 105 • 1 ≤ x[i].y[i] ≤ 10⁹ • 1 ≤ length of q[i] and c[i] ≤ 10 • Each character of all c[i] and q[i] is in the range ascii[a-z, 0-9, -] • All city name values, c[i], are unique • All cities have unique coordinates ▾ Sample Case 0 Sample Input STDIN 3 → c[] size n = 3 fastcity → c[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana xyz 3 ~ ~ ~ 23 23 23 3 1 10 20 3 Function xyz → x[] size n = 3 →x[] = [23, 23, 23]. →y[] size n = 3 →y[] = [1, 10, 201 →q[] size m = 3 fastcity → q[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana Sample Output bigbanana fastcity bigbanana A number of cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) coordinate intersection. City names and locations are given in the form of three arrays: c, x, and y, which are aligned by the index to provide the city name (c[i]), and its coordinates, (x[i], y[i]). Determine the name of the nearest city that shares either an x or a y coordinate with the queried city. If no other cities share an x or y coordinate, return 'NONE'. If two cities have the same distance to the queried city, q[i], consider the one with an alphabetically shorter name (i.e. 'ab' < 'aba'<'abb) as the closest choice. The distance is the Manhattan distance, the absolute difference in x plus the absolute difference in y. 5 4 C3 H 3 2 C2 1. 1 2 3 X y Example n = 3 c = ['c1', 'c2', 'c3'] x = [3, 2, 1] y = [3, 2, 3] q=['c1', 'c2', 'c3'] C1 4 5 The three points at (x[i], y[i]) are (3, 3), (2, 2) and (1, 3) represent the coordinates of the cities on the graph. The nearest city to c1 is c3, which shares a y value (distance = (3-1) + (3-3) = 2). City c2 does not have a nearest city as none share an xor y with c2, so this query returns 'NONE'. A query of c3 returns c1 based on the first calculation. The return array after all queries are complete is ['c3', 'NONE', 17. Function Description Complete the function closestStraightCity in the editor below. 1 > #!/bin/python3... 10 11 # 12 # Complete the closestStraightCity' function below. 13 14 15 16 17 18 19 20 21 22 23 # # The function is expected to return a STRING_ARRAY. # The function accepts following parameters: # 1. STRING ARRAY C # 2. INTEGER_ARRAY X # 3. INTEGER ARRAY y # 4. STRING_ARRAY q # def closestStraightCity (c, x, y, q): # Write your code here 24 25 > if __name__ == '__main__' Activate Windows Go to Settings to activate Windows. Function Description Complete the function closestStraightCity in the editor below. closestStraightCity has the following parameter(s): string c[n]: an array of strings that represent the names of each city[i] int x[n]: the x coordinates of each city[i] int y[n]: the y coordinates of each city[i] string q[m]: the names of each city to query Returns: string[m]: an array of m strings where the index of i element denotes the return value of the index of i query Constraints 1 ≤n, m≤ 105 • 1 ≤ x[i].y[i] ≤ 10⁹ • 1 ≤ length of q[i] and c[i] ≤ 10 • Each character of all c[i] and q[i] is in the range ascii[a-z, 0-9, -] • All city name values, c[i], are unique • All cities have unique coordinates ▾ Sample Case 0 Sample Input STDIN 3 → c[] size n = 3 fastcity → c[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana xyz 3 ~ ~ ~ 23 23 23 3 1 10 20 3 Function xyz → x[] size n = 3 →x[] = [23, 23, 23]. →y[] size n = 3 →y[] = [1, 10, 201 →q[] size m = 3 fastcity → q[] = ['fastcity', 'bigbanana', 'xyz'] bigbanana Sample Output bigbanana fastcity bigbanana
Expert Answer:
Answer rating: 100% (QA)
Heres the code for the closestStraightCity function def closestStraightCityc x y q Create dictionari... View the full answer
Related Book For
Organizational Behaviour Concepts Controversies Applications
ISBN: 978-0132310314
6th Canadian Edition
Authors: Nancy Langton, Stephen P. Robbins, Timothy A. Judge, Katherine Breward
Posted Date:
Students also viewed these programming questions
-
Average rate of return method, net present value method, and analysis for a service company The capital investment committee of Iguana Inc. is considering two capital investments. The estimated...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Jake, a single taxpayer, has $100,000 of ordinary income, a $10,000 net short-term capital loss, and $7,000 of qualified dividends. What is the result?
-
You are long 10 gold futures contracts, established at an initial settle price of $1,210 per ounce, where each contract represents 100 ounces. Over the subsequent four trading days, gold settles at...
-
Do leadership, organizational culture, and communication influence the effectiveness of organizational change programs? Discuss the effect that leadership behaviour, strong cultures, and personal and...
-
The financial statements of Gibson Corporation for the first two years of operations reflected the following amounts. Assume a tax rate of \(25 \%\) for 2020 and 2021. Estimates of future earnings at...
-
Ellen Bright, CEO of TWA Parts (TWAP), looked at the two balanced scorecards before her. One, from the luxury division, showed strong financial results; while the other, from the economy division,...
-
Compute the present value of the following cash flow stream. The discount rate is 0.07. Time 0: $7100 Time 1: $8600 Time 2: $5900 Time 3: $4500 Time 4: $7700 Round your answer, don't use decimals, $...
-
Sue and Dave always spend their evenings together, either cycling or playing computer games. On an evening with good weather, the probability that Sue prefers cycling is 0.7 and for Dave it is 0.4....
-
Think of an example or situation youve experienced as a consumer that was unethical. Look at it from the companys point of view. What is their rationale for operating in a socially or ethically...
-
A company manufactures rubber balls. The mean diameter of a ball is 12 cm with a standard deviation of 0.2 cm. Define the random variable X in words. X = ______________.
-
What is the z-score of x = 9, if it is 1.5 standard deviations to the left of the mean?
-
If the area to the left of x in a normal distribution is 0.123, what is the area to the right of x?
-
What is the probability of spending more than two days in recovery? a. 0.0580 b. 0.8447 c. 0.0553 d. 0.9420 The patient recovery time from a particular surgical procedure is normally distributed with...
-
What is the theoretical mean? A distribution is given as X ~ U(0, 12).
-
You have been made the purchasing manager of a local restaurant, Good Foods Take Away and Grill, that sells a mix of food items like burgers, pizzas and pasta. Answer the following questions with...
-
What kind of financial pressures can an LBO cause?
-
Japanese manufacturer Kyocera is implementing the 5S concept which is a workplace organization method focusing on efficiency and effectiveness. 5S program was developed in Japan as a tool for...
-
What is power? How do you get it?
-
Contrast distributive and procedural justice. What implications might they have for designing pay systems in different countries?
-
List three classes of short-term liability and two classes of long-term liability that will appear in the typical balance sheet.
-
Why is the matching principle important when preparing a profit and loss account and balance sheet?
-
What do you understand by Cronhelm's additivity principle and why does this prin- ciple tend to lead to the understatement of the net asset value of a company as shown in its balance sheet?
Study smarter with the SolutionInn App