Question
Given rectangular grid and the 3 types of pieces shown below, the object of Stretch is to place piece in the grid so that they
Given rectangular grid and the 3 types of pieces shown below, the object of Stretch is to place piece in the grid so that they from 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 of that piece.
? A piece can connect only at a tile with a circle and the tiles with the circles arc 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 cell, 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 arc 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 arc numbered consecutively starting with I in the upper left corner 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 I I. There are blocked cells at cells 23 and 37. Piece A is placed at 11. 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 1 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.
INPUT:
There will be 5 lines of data. Each line will contain the numbers.: r, c, s, n, followed by n 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 n numbers arc the cells that arc designated as blocked.
OUTPUT:
Form a path from the starting cell on the la 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 SAMPLE OUTPUT 1. ARAB
2. MBA
3. ABCA
4. ABCBB
5. BAA
12 5 6 7 8 9 10 A 15 16 17 18 19 20 21 22 BOO AC O 30 31 32 33 34 35 36 38 B 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 3 6 10 11 1 37 4 9 13 2 13 24 4 10 1 0 6 11 1 1 42 4 8 17 1 18.
Step by Step Solution
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
Code import javautilScanner import javaio import javautil public class Grid static int r new int5 st...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