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?
-
A physics student immerses one end of a copper rod in boiling water at 100C and the other end in an ice-water mixture at 0C. The sides of the rod are insulated. After steady-state conditions have...
-
Define and discuss substantive and procedural law.
-
Show that the two-sided p-value is \(1-\hat{F}_{T}\left(\left|t^{*} ight| ight)+\hat{F}_{T}\left(-\left|t^{*} ight| ight)\), where \(\hat{F}_{T}\) is the ECDF of the randomization distribution of...
-
Audit Report Deficiencies: Audits of Group Financial Statements and Other Operating Matters. Following is Rex Wolfs report on Bonair Corporations financial statements. Bonair publishes general-...
-
If you took $450,000 mortgage loan to be repaid over 30 years at 7.0%, calculate the amount of principal reduction in the first year.
-
The Sally Coffee Shop is considering closing one hour earlier in the evening through the week. Sally obtained the following data from a study taken last week of the number of customers between the...
-
Solve the equation. Check the solution. K 7 (4x-1)= 4 9 9
-
1. The main aspects of mathematical modeling of business operations. 2. The steps in the design and construction of mathematical models. 3. Sensitivity analysis models are two examples. 4....
-
Consider the following (X, Y) data: (53, 37), (34, 26), (10, 29), (63, 55), (28, 36). Find the regression equation
-
consider a binary symmetric source with the following channel matrix: [P(Y\X)] .8 [0,8 a] 1) Calculate the values of a, b and c. 2) Give the channel matrix and its diagram. 3) Calculate the output...
-
You are required to work out the annualised investment return required given a target wealth to be achieved some time in the future. For example, for a target wealth of $1,000,000 in 25 years time,...
-
You are a solutions design consultant at a major third-party logistics services provider (3PL). You have been recently engaged to provide advice to a client in the aviation sector. This client would...
-
Find the Electric displacement (D), Electric field (E), Polarization field [ P(r) ] of a dielectric sphere with uniform charge density: A dielectric sphere of permittivity & and radius R has a...
-
What did Lennox gain by integrating their WMS, TMS, and labor management systems?
-
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?
-
The accounting records of the Happy Tickers Sports and Social Club are in a mess. You manage to find the following information to help you prepare the accounts for the year to 31 December 2015. (1)...
-
The Milham Theatre Club has been in existence for a number of years. Members pay an annual subscription of 15 which entitles them to join trips to professional productions at a reduced rate. On 1...
-
Place a tick in the appropriate column for each of the following cost items: (a) Purchases of raw materials (b) Direct wages (c) General factory expenses (d) Depreciation of machinery (e) Commission...
Study smarter with the SolutionInn App