Question: Deadline may 6 pm NB solving this problem is not just about producing the correct output, it needs to use the most efficient algorithm and

Deadline may 6 pm

NB solving this problem is not just about producing the correct output, it needs to use the most efficient algorithm and data structures possible to solve the problem as if the solution is slow it will fail most of the test cases resulting in a poor grade as all my previous upload as suffered the same fate.

Deadline may 6 pm NB solving this problem is not just about

producing the correct output, it needs to use the most efficient algorithm

and data structures possible to solve the problem as if the solution

is slow it will fail most of the test cases resulting in

a poor grade as all my previous upload as suffered the same

fate. initial code in text format 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[][] thorns, int[][] squashes, int[][] passages,

initial code in text format

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[][] thorns, int[][] squashes, int[][] passages, int[] jump, int[] start) {

}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

int n = scanner.nextInt(); scanner.skip("( |[ \u2028\u2029\u0085])?");

// Read in plot dimensions: n lines of (r, c)

int[][] plotDims = new int[n][2];

for (int plotDimsRowItr = 0; plotDimsRowItr

for (int plotDimsColumnItr = 0; plotDimsColumnItr

int t = scanner.nextInt(); scanner.skip("( |[ \u2028\u2029\u0085])?");

// Read thorn locations: t lines of (i, x, y)

int[][] thorns = new int[t][3];

for (int thornsRowItr = 0; thornsRowItr

for (int thornsColumnItr = 0; thornsColumnItr

int s = scanner.nextInt(); scanner.skip("( |[ \u2028\u2029\u0085])?");

// Read squash locations: s lines of (i, x, y, q)

int[][] squashes = new int[s][4];

for (int squashesRowItr = 0; squashesRowItr

for (int squashesColumnItr = 0; squashesColumnItr

int m = scanner.nextInt(); scanner.skip("( |[ \u2028\u2029\u0085])?");

// Read passages m lines of ((i, x_i, y_i), (j, x_j, y_j))

int[][] passages = new int[m][6];

for (int passagesRowItr = 0; passagesRowItr

for (int passagesColumnItr = 0; passagesColumnItr

// Read in jump parameters a, b

int[] jump = new int[2];

String[] jumpItems = scanner.nextLine().split(" "); scanner.skip("( |[ \u2028\u2029\u0085])?");

for (int jumpItr = 0; jumpItr

// Read in starting point (pp, px, py)

int[] start = new int[3];

String[] startItems = scanner.nextLine().split(" "); scanner.skip("( |[ \u2028\u2029\u0085])?");

for (int startItr = 0; startItr

int result = findSquashes(plotDims, thorns, squashes, passages, jump, start);

bufferedWriter.write(String.valueOf(result)); bufferedWriter.newLine();

bufferedWriter.close();

scanner.close(); } }

Hop Squash: Mr. McGregor Fights Back Peter Rabbit has found himself back in Mr. McGregor's garden (again!) 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 thorny 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 thorny rose bush). Each cell may contain at most one hole. The passages beneath the holes may branch multiple times. Therefore it is possible 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 ith plot has r, row and c, columns. Each cel is uniquely defined by three integers: (i, 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 (i.e. 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 no 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!