Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Done in C please! Ferry Loading Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run

Done in C please!

image text in transcribedimage text in transcribed

Ferry Loading Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry crosses the river, and the cars exit from the other end of th e fe There is an -meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travels continuously back and forth between the banks so long as it is carrying a car or there is at least one car waiting at either bank. Whenever the ferry arrives at one of the banks, it unloads its cargo and loads up cars that are waiting to cross as long as they fit on its deck. The cars are loaded in the order of their arrival and the ferry's deck accommodates only one lane of cars. The ferry is initially on the left bank where it had mechanical problems and it took quite some time to fix it. In the meantime, lines of cars formed on both banks that wait to cross the river The first line of input contains c, the number of test cases. Each test case begins with the number I, a space and then the number m. m lines follow describing the cars that arrive in this order to be transported. Each line gives the length of a car (in centimeters), and the bank at which the car awaits the ferry ("left" or "right") For each test case, output one line giving the number of times the ferry has to cross the river in order to serve all waiting cars. Sample input 20 4 380 left 720 left 1340 right 1040 left 15 4 380 left 720 lefft 1340 right 1040 left 15 4 380 left 720 left 1340 left 1040 left 15 4 380 right 720 right 1340 right 1040 right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

2 To what extent does their relevance vary internationally?

Answered: 1 week ago

Question

2 What supply is and what affects it.

Answered: 1 week ago

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago