Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Efficient Janitor The janitor of a high school is extremely efficient. By the end of each day, all of the school's waste is

imageimageimage


1. Efficient Janitor The janitor of a high school is extremely efficient. By the end of each day, all of the school's waste is in plastic bags weighing between 1.01 pounds and 3.00 pounds. All plastic bags are then taken to the trash bins outside. One trip is described as selecting a number of bags which together do not weigh more than 3.00 pounds, dumping them in the outside trash can and returning to the school. Given the number of plastic bags n, and the weights of each bag, determine the minimum number of trips the janitor has to make. Example n = 5 weight = [1.01, 1.99, 2.5, 1.5, 1.01] The janitor can carry all plastic bags out in 3 trips: [1.01 +1.99, 2.5, 1.5 +1.01]. Function Description Complete the function efficientjanitor in the editor below. efficientjanitor has the following parameter(s): float weight[n]: weights of the bags Returns int: the minimum number of trips required Constraints 1 n 1000 1.01 weight[i] 3.0 Input Format For Custom Testing The first line contains an integer, n, the number of elements in weight. Each line i of the n subsequent lines (where 0i Sample Case 1 Sample Input For Custom Testing Function STDIN 4 weight [] size n = 4 1.01 weight = [1.01. 1.991, 1.32, 1.4] 1.991 1.32 1.4 Sample Output 3 Explanation The janitor can carry all plastic bags out in 3 trips: The 1st and 2nd plastics bags separately and the 3rd and 4th together

Step by Step Solution

3.51 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

We use Scanner class to take user input The function void readBagsWeight take user input the weights ... 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

Ethics in Information Technology

Authors: George Reynolds

5th edition

1285197151, 9781305142992 , 978-1285197159

More Books

Students also viewed these Programming questions

Question

What is ISO 9000?

Answered: 1 week ago

Question

Why do bars offer free peanuts?

Answered: 1 week ago

Question

7. For what kinds of patients is ECT recommended?

Answered: 1 week ago

Question

5. What are the effects of MAOIs?

Answered: 1 week ago