Стартовая точка в волновом поиске - C#
Формулировка задачи:
Вот код, есть стартовая точка, а как от нее начать
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List<int> lol = new List<int>();/// i stroka
List<int> lol1 = new List<int>();//// j stroka
int Start_i = 0;
int Start_j = 0;
int [,] map = new int[,]{
{1,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,1,1},
{0,0,0,0,0},
};
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
Console.Write(map[i,j] + " ");
}
Console.WriteLine();
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (map[i, j] == 1)
{
map[i, j] = -2;
}
if (map[i,j] == 0)
{
lol.Add(i);
lol1.Add(j);
Start_i = lol[0];
Start_j = lol1 [0];
}
}
}
Console.WriteLine();
Console.WriteLine("Start i " + Start_i + " " + "Strart j "+ Start_j);
Console.WriteLine();
Console.WriteLine(" obrabotanij massive");
int step = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
///какое условие надо что бы начиналось с стартовой точки
if (i + 1 < 5 && map[i + 1, j] != -2 && map[i + 1, j] == 0)
{
map[i + 1, j] = step + 1;
// step++;
}
if (j + 1 < 5 && map[i, j + 1] != -2 && map[i, j + 1] == 0)
{
map[i, j + 1] = step + 1;
//step++;
}
if (i - 1 > 0 && map[i - 1, j] != -2 && map[i - 1, j] == 0)
{
map[i - 1, j] = step + 1;
// step++;
}
if (j - 1 > 0 && map[i, j - 1] != -2 && map[i, j - 1] == 0)
{
map[i, j - 1] = step + 1;
//step++;
}
step++;
Console.Write(map[i,j] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}Решение задачи: «Стартовая точка в волновом поиске»
textual
Листинг программы
int [,] map = new int[,]{
{1,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,1,1},
{0,0,0,0,0},
};