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 boiler feed pump delivers 0.05 m3/s of water at 240C, 20 MPa. What is the mass flow rate (kg/s)? What would be the percent error if the properties of saturated liquid at 240C were used in the...
-
In its year-end physical inventory count, Tire Track Corporation forgot to count tires it had stored outside its warehouse in a trailer. As a result, ending inventory was understated by $7,000....
-
The following stock chart shows stock price performance for Coca-Cola over a two-week period. Note that May 16 and May 17 are a Saturday and a Sunday and are non-trading days. a. Which day seems to...
-
Dion, a shareholder, owned 20% of Meadow Brooks stock for 292 days and 25% for the remaining 73 days in the year. Using the per-day allocation method, compute Dions share of the following S...
-
Describe how an automatic sprinkler system can assist firefighters with fire extinguishment, and how does a fire engine connect to pump to the system?
-
Bug-Off Exterminators provides pest control services and sells extermination products manufactured by other companies. The following six-column table contains the company's unadjusted trial balance...
-
From the following information, prepare process cost accounts and normal loss, abnormal loss or gain accounts: Process A (Rs) Process B (Rs) Material 30,000 3,000 Labour 10,000 12,000 Overheads 7,000...
-
Booker is looking to buy a new vehicle for his business and wants a model that will last for 10 years. He finds one, and purchases it for $100,000, even though in this industry vehicles normally last...
-
Show the solution in good accounting form E10-5B: (Indicators of Liquidity and Leverage) Financial statements of CARROTS Corporation are reproduced below. The market price of Carrot's ordinary share...
-
Jude is organising a retirement party for his partner. He has found two suitable local venues which can accommodate his needs. The local hotel charges 15 per person for a buffet and 425 for a large...
-
Predict the product for the following reaction. CHGCH_NHS NCH.CHS COOH COOH (b) HO NHCH2CH N-CHCH c) COOH 'CONHCH.CHS
-
Make a Contact Us page as given in the following link : (HTML Doc) https://www.tune.com/contact-us/ You can skip the design part. However, the layout and content should be same. Do the Header and...
-
(12) 2. The list of 5 vectors B = (1, U2, U3, U4, Us) with ---0--0-0-H 2 3 = 1 1 = 2 spans R. Find a subset of B that is a basis of R. = 5 =
-
What are the key elements of a system investigation report?
-
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?
-
Deliberate the need for transformational or collaborative leadership in the next 5 years as the health care environment transforms as a result of industry reform.
-
It has been stated that to lead people through the complex changes facing the health care industry, transformational leadership is required (i.e., leaders creating an environment in which staff can...
-
If you were the director of a major department in a health care company, how important would each of the following activities be to you? Answer yes or no to indicate whether you would strive to...
Study smarter with the SolutionInn App