Question: Oracles are a mystical entity that can glimpse the future, but sadly, due to the burden of seeing the ever changing future, they have difficulty
Oracles are a mystical entity that can glimpse the future, but sadly, due to the burden of seeing
the ever changing future, they have difficulty conveying the future they see to others. Recently an
oracle at the school has informed you that one part of your most recent inscription is going to fail,
which is about the worst news you could get as magic resource archmage.
You have checked several parts of your inscription, and none are of a concern. You fear that
you might have little time before your inscription goes supernova, so you will check only the most
critical parts so that in the worst case you only lose a tree or two rather than the whole forest in
whatever magic calamity befalls the forest due to this mishap. To aid in your quest to find the
worst possible mistake we refer to the following basics of inscription making,
Inscriptions are composed of free and closed points of a dimensional grid. our current
inscription is Euclidean, which makes our life easier
Magic can directly flow between adjacent in one of the cardinal directions, ie up down,
left, or right free points.
Magic can indirectly flow between free points if their is a chain of adjacent free points that
connect them.
If magic directly flows between points, then it also indirectly flows between them as
well.
Magic will always indirectly flow from a free point to itself.
Magic generatedconsumed by the inscription is equal to the number of pairs of free points
that can allow for magic to indirectly flow between them.
Pairs are counted only once flowing from x to y is the same as flowing from y to x
We will denote closed points using # and free points using Consider the following inscrip
tion.
#####
##
#####
###
#####
Label the free points with integers starting from going from top to bottom and left to right.
The free point can reach and pairs
The free point can reach and pairs
The free point can reach pair
The free point can reach and pairs
The free point can reach pair
The total pairs implies that the given inscription has a total of magic generationconsump
tion.
A closed point that fails behaves like a free point. If a single closed point fails in the above in
scription, there are multiple possible resulting inscription. Below is one possible way the inscription
can could have a free point fail.
#####
##
####
###
#####
In the failing inscription above there are total magic generationconsumption In general,
the more magic generatedconsumed the worse the outcome of the failure. A worse outcome would
be the following inscription,
#####
##
####
###
#####
The above inscription generatesconsumes magic.
The exterior of the inscription, and potentially some of the internal closed points, have been
checked for failures, but the failure has not been found. It would be nice to know the magic
generated in the worst possible single failure.
Problem
Please write a program that takes in an inscription description with the locations of possible points
of failure and returns the maximum magic generated by a single failure at a possible point.
Input Specification
Input begins with a line containing integers, R and C R C representing the
numbers of rows and columns of the inscription.
The following R lines each contain C characters. The characters will be one of the following
#X or denoting a checked closed point, a closed point that could fail, or a free point.
Output Specification
Output the maximum total magic that could be generatedconsumed by a single failure at an
uncheck closed point.
Example Input Output
Below is are example of cases that your program will be tested against. The below cases are not
meant to be extensive. It is your responsibility. You should work on developing your own cases.
Input Output
#####
##
##XX#
###
#####
#######
###
#X#X#
#######
Example Explanation
Sample Case
In the first case there are rows and columns. The grid resembles the grid given in the problem
description. There are only possible points of failures. The worst case is when the center point
fails. If the center fails the total number of pairs of indirectly flowing magic is
Sample Case
In the second case there are rows and columns. There are again possible points of failure.
In other cases there may be more or less than possible points given. In this case the rightmost
point. will not indirectly allow magic to flow between all the free points, but neither will the
leftmost point. The reason is because free points cannot directly flow across diagonals. The best
point of failure is the leftmost unchecked closed point. points are indirectly flowing on the left
pairs and points are indirectly flowing on the left pairs
Hints
Use floodf
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
