Answered step by step
Verified Expert Solution
Question
1 Approved Answer
RubbleRover You have built a small robot named RubbleRover, which collects trash and has a radar. You want to use it for recycling. Here is
RubbleRover
You have built a small robot named RubbleRover, which collects trash and has a radar. You want to use it for recycling. Here is what you need to know.
There are garbage blocks lined up In a row, with equal distance between them.
RubbleRover can tell if there is a garbage block at a certain distance from it If it finds a block, it moves to that block and collects it
If RubbleRover cannot tell if the garbage is on its left or right, it will not go there to save energy and work efficiently.
RubbleRover will keep checking further if it is unsure about the garbage's location.
You are given the following:
The first line tells where RubbleRover starts, P
The second line tells how many positions have
Garbage.
The third line has an array of s and where means there is garbage and means there is no garbage.
Your job is to figure out how many garbage blocks RubbleRover will recycle while being most efficient.
Input
Output
Explanation: RubbleRover is located in the rd position.
As the third line of the Input above shows, there is a garbage block at the rd position, RubbleRover is sure about it So RubbleRover will recycle it
RubbleRover knows that there is one garbage block at a distance from it but it cannot determine whether it should go to the left or right. So it will not check these positions.
RubbleRover starts checking further and sees that there are two garbage blocks at a distance of from It Since one position can have only one garbage block, RubbleRover is sure that one is to its left and the other is to the right. So it will recycle both of these garbage blacks.
The answer is RubbleRover will recycle
for input
Input
Output
Explanation: RubbleRover is located in the th position.
As the third line of the input above shows, there is no garbage block in the th position.
There is one garbage block at a distance of from RubbleRover, and RubbleRover is sure that it is located to its left since there are only four garbage blocks RubbleRover will recycle that garbage block.
The same is true for a distance of from RubbleRover,
There is no garbage block at distance from RubbleRover.
The answeris RubbleRover will recycle
Barbage blocks in this case
write a program in java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started