Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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[][]
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
String[] plotDimsRowItems = scanner.nextLine().split(" ");
scanner.skip("( |[ \u2028\u2029\u0085])?");
for (int plotDimsColumnItr = 0; plotDimsColumnItr
int plotDimsItem = Integer.parseInt(plotDimsRowItems[plotDimsColumnItr]);
plotDims[plotDimsRowItr][plotDimsColumnItr] = plotDimsItem;
}
}
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
String[] thornsRowItems = scanner.nextLine().split(" ");
scanner.skip("( |[ \u2028\u2029\u0085])?");
for (int thornsColumnItr = 0; thornsColumnItr
int thornsItem = Integer.parseInt(thornsRowItems[thornsColumnItr]);
thorns[thornsRowItr][thornsColumnItr] = thornsItem;
}
}
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
String[] squashesRowItems = scanner.nextLine().split(" ");
scanner.skip("( |[ \u2028\u2029\u0085])?");
for (int squashesColumnItr = 0; squashesColumnItr
int squashesItem = Integer.parseInt(squashesRowItems[squashesColumnItr]);
squashes[squashesRowItr][squashesColumnItr] = squashesItem;
}
}
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
String[] passagesRowItems = scanner.nextLine().split(" ");
scanner.skip("( |[ \u2028\u2029\u0085])?");
for (int passagesColumnItr = 0; passagesColumnItr
int passagesItem = Integer.parseInt(passagesRowItems[passagesColumnItr]);
passages[passagesRowItr][passagesColumnItr] = passagesItem;
}
}
// 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
int jumpItem = Integer.parseInt(jumpItems[jumpItr]);
jump[jumpItr] = jumpItem;
}
// 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 startItem = Integer.parseInt(startItems[startItr]);
start[startItr] = startItem;
}
int result = findSquashes(plotDims, thorns, squashes, passages, jump, start);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedWriter.close();
scanner.close();
}
}
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