Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-Important- This problem should be done in JAVA only PROBLEM: Given a rectangular grid and the 3 types of pieces shown below, the object of

-Important-
This problem should be done in JAVA only
image text in transcribed
image text in transcribed
image text in transcribed
PROBLEM: Given a rectangular grid and the 3 types of pieces shown below, the object of Stretch is to place pieces in the grid so that they form a connected path from the left side to the right side. A piece cannot be rotated or flipped. A piece can only connect to the last piece that was placed and one column to the right ofthat picce A piece can connect only at a tile with a circle and the tiles with the eircles are the only tiles that are allowed to touch. All tiles of the connecting piece must be to the right of all previously placed pieces. A piece cannot be placed in the grid such that it would cover any part of another piece, cover a blocked cel, or extend beyond the grid. . * . The first piece can only touch the starting side at one circle tile The final piece can only touch the right side at one circle tile. Pieces are placed in alphabetical order. If a piece does not fit, skip it and use the next piece that fits. When Piece C is either used or skipped, then begin again with Piece A . Grid cells are numbered consecutively starting with 1 in the upper left comer as shown. . We guarantee that if a piece can be placed, then that will be the only location it can be placed EXAMPLE: The following example is a 6 x 10 grid with a starting cell of 11. There are blocked cells at cells 23 and 37. Piece A is placed at 1. Piece B can only be placed at 14. The next piece must connect at 26. Piece C cannot be placed at 26 because there is a blocked cell at 37. Therefore, Piece C is skipped Piece A is placed at Location 26. The next piece must connect at 29. Piece B is placed at 29 and touches the right side at 40. Therefore, the path is ABAB 1 2 3 45 6 7 89 10 ATO15 16 17 18 19 20 21 22 31 3233 34 35 36 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 38 B INPUT: There will be 5 lines of data. Each line will contain the numbers: r,c,s, , followed by m numbers. r indicates the number of rows in the grid. c indicates the number of columns in the grid. s indicates the starting cell number for the first piece. n indicates the number of blocked cells, and the next numbers are the cells that are designated as blocked OUTPUT: Form a path from the starting cell on the left side of the grid to a single cell on the opposite edge of the grid using the algorithm above. Print the sequence of pieces that were used to form the path SAMPLE INPUT 6 10 11 1 37 4913 2 13 24 4 10 10 SAMPLE OUTPUT 1. ABAB 3. ABCA 4. ABCBB 5. BAA TEST INPUT 7 12 25 2 40 55 5 10 14 2 14 36 39 6 9 10 2 22 34 515 16 2 17 49 6 10 21 0 TEST OUTPUT: 1. 3. ACBB 4. BABABA 5. ABCA

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started