You describe the following sample test case 1
input:
1
4 2
r r b b
b b b r
r b r b
r b b r
output:
7
1
4 2
r r b b
b b b r
r b r b
r b b r
Before you start solve the example without coding and try to get result.
To solve the problem, as always, it must be broken down into small parts or subtasks.
Subprograms or methods are then written for the individual subtasks.
The solutions in C++ and Java will differ significantly. You'll have to choose one of the two and have to present us with at least a first draft of the programme.
Obvious subtasks would be e.g. reading in the file, creating a matrix as well as
the output of the matrix for control.
When solving, you should probably pay attention to the opponents first
with the greatest distance to take care of it so that you catch as many as possible.