aligatorimatori
aligatorimatori
CC#
Created by aligatorimatori on 12/6/2023 in #help
Hey guys I need some troubleshooting with a C# task using BFS
I have a task that I's mostly working but sometimes I have undesirable outputs and not behaving right I didnt wanted to spam the chats so I asked here the task goes:
The input parameter n denotes a number that determines the size of the matrix.
E.g. n=3 means there is a 3x3 matrix.
There are Pokemon on certain fields in the matrix.
The input parameter x denotes an array of integers representing the x coordinates of the Pokemon in the matrix.
The input parameter y denotes an array of integers representing the y coordinates of the Pokemon in the matrix.
Fill and return the matrix so that each cell represents the minimum distance to the nearest Pokemon.
Distance is calculated only vertically and horizontally. Diagonal distance is presented as e.g. one horizontal and one vertical (2 in total).
Example 1:

n=3
x=[1]
y=[1]

The result
2,1,2
1,0,1
2,1,2

Example 2:
n=5
x=[1,4]
y=[1,3]

The result

2,1,2,3,3
1,0,1,2,2
2,1,2,2,1
3,2,2,1,0
4,3,3,2,1
The input parameter n denotes a number that determines the size of the matrix.
E.g. n=3 means there is a 3x3 matrix.
There are Pokemon on certain fields in the matrix.
The input parameter x denotes an array of integers representing the x coordinates of the Pokemon in the matrix.
The input parameter y denotes an array of integers representing the y coordinates of the Pokemon in the matrix.
Fill and return the matrix so that each cell represents the minimum distance to the nearest Pokemon.
Distance is calculated only vertically and horizontally. Diagonal distance is presented as e.g. one horizontal and one vertical (2 in total).
Example 1:

n=3
x=[1]
y=[1]

The result
2,1,2
1,0,1
2,1,2

Example 2:
n=5
x=[1,4]
y=[1,3]

The result

2,1,2,3,3
1,0,1,2,2
2,1,2,2,1
3,2,2,1,0
4,3,3,2,1
And the solution is in C# and in the chat It was too long to send: the problem for it doesn't output the second example this is the example
this is the output on the second example:
Example 2:
2 1 2 3 4
1 0 1 2 3
2 1 2 2 3
3 2 2 1 2
3 2 1 0 1
the result should be:
2,1,2,3,3
1,0,1,2,2
2,1,2,2,1
3,2,2,1,0
4,3,3,2,1
this is the output on the second example:
Example 2:
2 1 2 3 4
1 0 1 2 3
2 1 2 2 3
3 2 2 1 2
3 2 1 0 1
the result should be:
2,1,2,3,3
1,0,1,2,2
2,1,2,2,1
3,2,2,1,0
4,3,3,2,1
Thank you for any help in advance just trying to learn something advance💟
6 replies