using System.Collections.Generic;
public static void Main()
string take1 = Console.ReadLine();
string take2 = Console.ReadLine();
while (!Size.init(take1, take2))
take1 = Console.ReadLine();
take2 = Console.ReadLine();
List<Ship> Ships = new List<Ship>();
for (int i = 1; i < 5; i++)
for (int j = i; j < 5; j++)
var f = SetShipOnField(Size.H(), Size.W(), Ships);
for (int i = 0; i < Size.H(); i++)
for (int j = 0; j < Size.W(); j++)
Console.Write(f[i, j].ToString() + " ");
private static bool[,] SetShipOnField(int height, int width, List<Ship> ships)
bool[,] field = new bool[height, width];
bool[,] fieldMore = new bool[height, width];
foreach (Ship now in ships)
if (!Go(height, width, field, fieldMore, now))
Console.WriteLine("уместить коробли не возможно");
private static bool Go(int h, int w, bool[,] field, bool[,] fieldMore, Ship now)
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (CanSet(h, w, fieldMore, i, j, true, now))
Set(h, w, field, fieldMore, i, j, true, now);
else if (CanSet(h, w, fieldMore, i, j, false, now))
Set(h, w, field, fieldMore, i, j, false, now);
private static bool CanSet(int h, int w, bool[,] field, int i, int j, bool direction, Ship ship)
for (int k = 0; k < ship.l; k++)
for (int k = 0; k < ship.l; k++)
private static void Set(int h, int w, bool[,] field, bool[,] fieldMore, int i, int j, bool direction, Ship ship)
for (int k = 0; k < ship.l; k++)
fieldMore[k + i, j] = true;
fieldMore[k + i + 1, j] = true;
fieldMore[k + i, j - 1] = true;
fieldMore[k + i, j + 1] = true;
for (int k = 0; k < ship.l; k++)
fieldMore[i, k + j] = true;
fieldMore[i, k + j + 1] = true;
fieldMore[i - 1, k + j] = true;
fieldMore[i + 1, k + j] = true;
static public bool init(string val1, string val2)
if (!Int32.TryParse(val1, out h))
if (!Int32.TryParse(val2, out w))
public int l { get; private set; }