In python or C++ 2. Busy intersection There is a busy intersection between two one-way streets: Main
Fantastic news! We've Found the answer you've been seeking!
Question:
In python or C++
Transcribed Image Text:
2. Busy intersection There is a busy intersection between two one-way streets: Main Street and 1st Avenue. Cars passing through the intersection can only pass through one at a time. When multiple cars arrive at the intersection at the same time, two queues can build up -- one for each street. Cars are added to the queue in the order at which they arrive. Unfortunately, there is no traffic light to help control traffic when multiple cars arrive at the same time. So, the local residents have devised their own system for determining which car has priority to pass through the intersection: • If in the previous second, no car passed through the intersection, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on 1st Avenue, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on Main Street, then the first car in the queue for Main Street goest first. Passing through the intersection takes 1 second. For each car, find the time when they will pass through the intersection. Function Description Complete the function getResult in the editor below. getResult has the following parameters: int arrival[n]: an array of n integers where the value at index i is the time in seconds when the th car arrives at the intersection. If arrival[i] = arrival[j] and i <j, then car i arrives before car j. int street[n]: an array of n integers where the value at indexi is the street on which the ith car is traveling: 0 for Main Street and 1 for 1st Avenue. Returns: int[n]: an array of n integers where the value at index i is the time when the ith car will pass through the intersection Constraints • 1≤n≤105 • 0 ≤ arrival[i] ≤ 10⁹ for 0≤i≤n-1 • arrival[i] ≤ arrival[i+1] for Osi≤n-2 • 0≤ street[i] ≤ 1 for Osi≤n-1 2. Busy intersection There is a busy intersection between two one-way streets: Main Street and 1st Avenue. Cars passing through the intersection can only pass through one at a time. When multiple cars arrive at the intersection at the same time, two queues can build up -- one for each street. Cars are added to the queue in the order at which they arrive. Unfortunately, there is no traffic light to help control traffic when multiple cars arrive at the same time. So, the local residents have devised their own system for determining which car has priority to pass through the intersection: • If in the previous second, no car passed through the intersection, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on 1st Avenue, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on Main Street, then the first car in the queue for Main Street goest first. Passing through the intersection takes 1 second. For each car, find the time when they will pass through the intersection. Function Description Complete the function getResult in the editor below. getResult has the following parameters: int arrival[n]: an array of n integers where the value at index i is the time in seconds when the th car arrives at the intersection. If arrival[i] = arrival[j] and i <j, then car i arrives before car j. int street[n]: an array of n integers where the value at indexi is the street on which the ith car is traveling: 0 for Main Street and 1 for 1st Avenue. Returns: int[n]: an array of n integers where the value at index i is the time when the ith car will pass through the intersection Constraints • 1≤n≤105 • 0 ≤ arrival[i] ≤ 10⁹ for 0≤i≤n-1 • arrival[i] ≤ arrival[i+1] for Osi≤n-2 • 0≤ street[i] ≤ 1 for Osi≤n-1
Expert Answer:
Answer rating: 100% (QA)
To solve this problem we can simulate the process of cars passing through the intersection We will maintain two queues one for each street to keep tra... View the full answer
Related Book For
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg
Posted Date:
Students also viewed these programming questions
-
Python Company leased equipment from Hope Leasing on January 1, 2011. Hope purchased the equipment at a cost of $222,666. There is no expected residual value. Required: Prepare appropriate journal...
-
Python Machine Company is considering the acquisition of a large equipment to set up its factory in a backward region for Rs. 1,900,000. The equipment is expected to have an economic useful life of...
-
In this assignment, you will write a Python program that asks the user for a list of words, and then prints the shortest word, the longest word, and the average length of the words. Here is a sample...
-
A bank reconciliation takes time and must balance. An employee was struggling in balancing the bank reconciliation. Her supervisor told her to plug (make an unsupported entry for) the difference,...
-
(a) Storm Corporation purchased a new machine on October 31, 2010. A $1,200 down payment was made and three monthly installments of $3,600 each are to be made beginning on November 30, 2010. The cash...
-
The number of ships to arrive at a harbor on any given day is a random variable represented by x. The probability distribution for x is as follows: Find the probability of the following for any a...
-
Kelly Inc. leased equipment, originally reported in inventory, to General Engines Inc. for a 4-year lease term and recorded the lease as a sales-type lease. At the expiration of the lease, the...
-
U3 Company is considering three long-term capital investment proposals. Each investment has a useful life of 5 years. Relevant data on each project are as follows. Depreciation is computed by the...
-
B. 1. Perform a vertical analysis for each course. Round your percentages to one decimal place. Bluff Run Golf Courses Revenues Income Statement Month Ending July 31, 2018 Course Blue Course Black...
-
Axon Corporation, which has three divisions, is preparing its sales budget. Each division expects a different growth rate because economic conditions vary in different regions of the country. The...
-
Consider a market with two consumers and one good. Person 1's demand curve is P = 1-2, where P is the price and 21 is the amount of the good consumed by person 1. Likewise, Person 2's demand curve is...
-
Why did the U.S government change its treatment of income earned by foreign subsidiaries of U.S. corporations? Eager to benefit from the economic growth and the job creation that foreign direct...
-
How to enforce a settlement agreement?
-
What do you see as the basic advantages and disadvantages of each system? Assume you are the top HR manager for a large international firm. The head of your companys operation in Japan has just...
-
How does HRM in the United States differ from HRM in Japan? Assume you are the top HR manager for a large international firm. The head of your companys operation in Japan has just resigned...
-
How to draft a settlement agreement?
-
18. The Generic Genetic (GG) Corporation pays no cash dividends currently and is not expected to for the next 4 years. Its latest EPS was $5, all of which was reinvested in the company. The firm's...
-
Write each fraction as a percent. 7 50
-
a.-d. Repeat Problem 16 using LN_BLDTL as the response and LN_BRNTL as the predictor.
-
The following table presents the weight (X1), age (X2), and plasma lipid levels of total cholesterol (Y) for a hypothetical sample of 25 patients suffering from hyperlipoproteinemia, before drug...
-
The promotional policies of four companies in a certain industry were compared to determine whether their rates for promoting blacks and whites differed. Data on the variable "rate discrepancy" were...
-
Consider the following three separate scenarios for a one-year, \(\$ 100,000\) note payable issued on September \(1,2020\). Use the straight-line method to amortize any discount on note payable....
-
Masy's Department Store supported its operations through short-term note financing in 2020 described as follows: May 10 The Company entered into a new credit agreement with certain financial...
-
The following table includes five separate short-term note payable scenarios. Required For each separate scenario, complete the last column in the table by calculating interest expense accrued at the...
Study smarter with the SolutionInn App