Question: import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Solution { // Complete the findSquashes function below. static int findSquashes(int[][] plotDims, int[][]
Hop Squash: Mr. McGregor Fights Back Peter Rabbit has found himself back in Mr. McGregor's garden (againl) but to his surprise, Mr. McGregor has made some changes after Peter's last raid. Instead of being organised in a single grid, the garden has now been partitioned into n plots, and each is organised as a grid of vegetable patches, with its own fence surrounding it The fencing is too high for Peter to jump over. Moreover, Mr. McGregor has cultivated patches of thomy roses at certain cells of the grid. These would be very painful for Peter to land on when he jumps, so he must avoid landing on those cells at all costs. While these interventions from Mr. McGregor are potent deterrents, his famous Butternut Squash too tasty to keep many a brave rabbit from trying to circumvent them As a consequence, a whole network of tunnels now exists beneath the plots, allowing Peter to burrow his way between the enclosed plots The burrows open up as holes in the plots. A hole will always be located in a vegetable patch (never in a thomy rose bush). Each cell may contain at most one hole. The passages beneath the holes may branch multiple times. Therefore it is possible fora hole in one garden to lead to one or more holes in other plots A single plot may contain multiple holes, and it is possible that a hole in a plot leads to another hole within the same plot. Plots are numbered from 1 to n. The i plot has r, rows and c, columns. Each cell is uniquely defined by three integers: d x y) to indicate that it is located in garden i at row x and column y. The positions x and y are always relative to the origin (top left corner) of plot i, and are 0-based. (Increasing coordinates are to the right and down) Coordinates like these are used to describe the locations of the holes, and the cells growing butternut squash and thorny roses. The locations of the butternut squash cells are presented along with a 4th integer to indicate the number of butternut squashes grown at that cell. When Peter jumps, he moves a cells in one direction and b cells in an orthogonal direction (ie. at right angles to the original movement). If his landing square would either be on a rose bush or outside of the plot that he is currently in, then he does not make the jump in that direction. In order for Peter to burrow, he must be located at a cell that contains a hole, and after he finishes moving, he will be at a hole on the other end of the burrow that he entered. Given a description of the dimensions of the plots, the burrows between them, the quantity and location of all the butternut squashes in the gardens, Peter's starting location and his jump characteristics, determine the maximum number of butternut squashes that he could collect. Input Format Line 1 contains a single integer n the number of plots The next n lines each contains a pair of integers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
