Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Computer Science is so hard these days that students in a senior design group have decided to work on a project to have drones fly
Computer Science is so hard these days that students in a senior design group have decided to work on a project to have drones fly them dinner while they are hard at work on their coursework. Naturally, the senior design group would like to offer this feature for multiple groups of people,
each of who may be located in different places and might want food from different places.
The group did a great job with their drone design. It flawlessly picked up food and could fly that
food to the appropriate location. Unfortunately, they only built one remote control for the upto
four drones to deliver food. That means that even if best path for two drones is different, the drones
are limited to moving in the same direction each time. Of course, if this were always true, then the
drones would rarely be able to complete all of their deliveries. Luckily, however, some areas of
the sky are marked as nofly zones. Thus, if a drone is directed to move into one of these nofly
zones, instead of moving, it will stay put. This means that with just one controller, different drones
might end up moving different paths. Also, once a drone successfully delivers food to its senior
design group, it will ignore all future commands and stay put.
We can model the map the drones will be navigating as an by grid, where some squares are
marked as nofly zones, some squares are the starting spots for the drones this is the restaurant
from which they pick up food and some squares are the locations of the senior design groups:
G
D D
XX XX
G
G
D
XX
In the grid above, there are three drones delivering meals to three senior design groups. The drones
are numbered D through D and the senior design groups are numbered G through G The
drone Dx is delivering food to the group Gx
The remove control allows the drones to move north up south down east right and west left
a single grid square. For example, if we hit the down button twice, the new state of our grid is
G
XX XX
D A
G
D
XX
After two moves, the first drone has successfully delivered its food. This is denoted by A for
arriving above. The second drone has also moved down two squares and is one square away from
its destination. The third drone has moved down only one square because when the remote told it
to go down the second time, the third drone saw that the square below was a nofly zone.
After a third move down, the second drove delivers its food:
G
XX XX
A
A
D
XX
From here, the shortest route for the third drove to deliver its food takes moves. One such
sequence is up up up left, up up up right, right. In total using this set of button presses, it takes
button presses to get all three drones to successfully deliver its food.
Some other notes:
The entire by grid is surrounded by nofly zone squares not drawn in but just assumed to
be there.
Two drones may occupy the same grid square at the same time so long as its not a nofly zone
square.
A drone treats each groups location except for the one its delivering to as a nofly zone. It
would be unfair to tempt students in the wrong group with food and then just fly through.
The Problem:
Given the initial state of the by grid, showing the initial locations of the drones, the locations
each of the drones must deliver their food and the nofly zone squares, determine the fewest
number of remote control button presses necessary to have all of the drones successfully deliver
their food. If this is impossible, determine that the task is not possible.
The Input:
The first line of input contains a single integer, n n representing the number of drones
for the input case. The corresponding drones are labeled D through Dn and the corresponding
groups to which they are delivering food are labeled G through Dn
The following eight lines each contain space separated strings of two characters each,
representing that row of the input grid. If the two characters are the grid square is an open
square. If the two characters are Dk where k is a digit in between and n then that represents
drone ks starting position. If the two characters are Gk where k is a digit in between and n
then that represents the destination drone k is delivering food. Finally, if the two characters are
XX that means the co
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