Description On an nxn map, there are some weird patterns. The same numbers are connected into a pattern, ensure that the same numbers are connected. Connectivity is defined as-if two squares share an edge, then the two squares are connected; if A and B are connected, B and C Connected, then A and C are connected. Different numbers compose multiple patterns, as shown in the figure

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please use JAVA to solve this question, Thanks!!! 

2. Move the patterns
Description
ALL
On an nxn map, there are some weird patterns.
The same numbers are connected into a pattern, ensure that the same
numbers are connected. Connectivity is defined as-if two squares
share an edge, then the two squares are connected; if A and B are
connected, B and C Connected, then A and C are connected.
1
Different numbers compose multiple patterns, as shown in the figure
below:
3
1
4 4
4
1
4 4
2 2
4 4
Then there are k operations, which are executed in sequence. Each
operation will move a specified pattern by a unit distance in one
direction. If the movement will be blocked by other patterns or move
out of the map boundary, this movement will fail and this operation
will be ignored.
135 left
seconds left
There are two numbers in the first line, n and k
Next n lines, each line has n characters. The character 0 means that
the grid is empty, and the characters 1 to 9 indicate that the
numbered pattern occupies this grid.
In the next k lines, each line has a number from 1 to 9 and a capital
ALL
letter. The number represents the number of the pattern to be
operated. L stands for moving one square to the left; U stands for
moving up one square; R stands for moving one square to the right; D
stands for moving down one square.
1
Output
An nxn map, representing the final appearance of the map after k
2
operations
Sample Input
3
84
00000000
10044000
10040000
10040000
00440220
00040020
00044030
00000000
1 L
2 D
3R
1 U
Sample Output
10000000
10044000
10040000
00040000
00440220
00040020
00044003
00000000
Data range
For 30% of the data, n <= 10^2, k <= 10^2, the number of squares in
each pattern <=10
For 100% data, n <= 10^3, k <= 10^3, the number of squares in each
pattern <=10^3
Transcribed Image Text:2. Move the patterns Description ALL On an nxn map, there are some weird patterns. The same numbers are connected into a pattern, ensure that the same numbers are connected. Connectivity is defined as-if two squares share an edge, then the two squares are connected; if A and B are connected, B and C Connected, then A and C are connected. 1 Different numbers compose multiple patterns, as shown in the figure below: 3 1 4 4 4 1 4 4 2 2 4 4 Then there are k operations, which are executed in sequence. Each operation will move a specified pattern by a unit distance in one direction. If the movement will be blocked by other patterns or move out of the map boundary, this movement will fail and this operation will be ignored. 135 left seconds left There are two numbers in the first line, n and k Next n lines, each line has n characters. The character 0 means that the grid is empty, and the characters 1 to 9 indicate that the numbered pattern occupies this grid. In the next k lines, each line has a number from 1 to 9 and a capital ALL letter. The number represents the number of the pattern to be operated. L stands for moving one square to the left; U stands for moving up one square; R stands for moving one square to the right; D stands for moving down one square. 1 Output An nxn map, representing the final appearance of the map after k 2 operations Sample Input 3 84 00000000 10044000 10040000 10040000 00440220 00040020 00044030 00000000 1 L 2 D 3R 1 U Sample Output 10000000 10044000 10040000 00040000 00440220 00040020 00044003 00000000 Data range For 30% of the data, n <= 10^2, k <= 10^2, the number of squares in each pattern <=10 For 100% data, n <= 10^3, k <= 10^3, the number of squares in each pattern <=10^3
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY