Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, this might look too long but I'm just trying to solve the prazor problem on kattis and I have a starter template below so

Hi, this might look too long but I'm just trying to solve the prazor problem on kattis and I have a starter template below so according to this template I need to implement PlaceRacket and then implement deadFlies which is in the last part of the code. if there is anything else needed please let me know.

import java.util.*; /** Solves the prozor problem on open kattis * */ public class Prozor { public static void main(String[] args) { Scanner in = new Scanner(System.in); final int R = in.nextInt(); // number of rows in the input board final int S = in.nextInt(); // number of columns in the input board final int K = in.nextInt(); // size of paddle (width or height) final char[][] board = new char[R][S]; // will hold input board for problem // fill board in.nextLine(); // waste the end of the first line for(var row = 0; row < R; row++) { var line = in.nextLine(); for(var col=0; col < S; col++) { board[row][col] = line.charAt(col); } } // kill flies in every way possible var maxFlies = 0; var outputBoard = board; for(var row = 0; row <= R-K; row++) { for(var col = 0; col <= S-K; col++) { var newBoard = copyBoard(board); // copy the original board placeRacket(newBoard, row, col, K); // smack the racket on to the flies var flies = deadFlies(newBoard, row, col, K); // count how many you got if (flies > maxFlies) { // maximize dead flies, remember the placement outputBoard = newBoard; maxFlies = flies; } } } // print the results for maximum extermination System.out.println(maxFlies); printBoard(outputBoard); } /** prints out a character matrix representing a board for the problem */ public static void printBoard(char[][] board) { for(int row=0; rowFirst implement placeRacket Then implement deadFlies. /** sets the racket on to the board * * @param board board to alter with racket image * @param row upper left hand corner of the racket (row) * @param col upper left hand corner of the racket (column) * @param K size (width or height) of racket */ public static void placeRacket(char[][] board, int row, int col, int K) { // TODO: implement } /** counts the number of dead flies on a board with a racket on it * * @param board board with racket imprinted on it * @return number of flies squished by the racket */ public static int deadFlies(char[][] board, int row, int col, int K) { return 0; // TODO: implement } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions