Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.69 KB | None | 0 0
  1. program municip2018n5;
  2.  
  3. var
  4.   N, M, i, j, Hx, Hy, x, y, ans, num, Wx, Wy: integer;
  5.   inp: char;
  6.   W, H: array[,] of integer;
  7.  
  8. begin
  9.   readln(N);
  10.   readln(M);
  11.   //выделяем память под динамические массивы
  12.   Setlength(W, M, N);
  13.   Setlength(H, M, N);
  14.   //читаем H
  15.   for i := 0 to N - 1 do
  16.   begin
  17.     for j := 0 to M - 1 do
  18.     begin
  19.       read(inp);
  20.       if inp = 'H' then
  21.         H[j, i] := 1
  22.       else
  23.         H[j, i] := 0;
  24.     end;
  25.     readln();
  26.   end;
  27.   //читаем W
  28.   for i := 0 to N - 1 do
  29.   begin
  30.     for j := 0 to M - 1 do
  31.     begin
  32.       read(inp);
  33.       if inp = 'W' then
  34.         W[j, i] := 1
  35.       else
  36.         W[j, i] := 0;
  37.     end;
  38.     readln();
  39.   end;
  40.  
  41.   //Помещаем воду в (0;0) -> (M;N); Перебираем положение дома по крайней точке слева снизу (-M;-N) -> (M;N)
  42.   for Hx := -M to M + 1 do
  43.   begin
  44.     for Hy := -N to N + 1 do
  45.     begin
  46.       //Получили значение для крайней точки дома - (Hx,Hy);
  47.       //Нужно перебрать все x и y для дома (сравниваем с озером)
  48.       num := 0;
  49.       for x := 0 to M - 1 do
  50.       begin
  51.         for y := 0 to N - 1 do
  52.         begin
  53.           //num  считает количество общих ребер у дома и озера
  54.           //рассматриваем клетки где есть дом
  55.           if H[x, y] = 1 then
  56.           begin
  57.             Wx := Hx + x;
  58.             Wy := Hy + y;
  59.             if (Wx >= 0) and (Wx < M) and (Wy >= 0) and (Wy < N) then
  60.             begin
  61.               if W[Wx, Wy] = 1 then
  62.                 num := -2147483648 //отметаем случай где вода накладывается на дом
  63.               else
  64.               begin
  65.                 // рассматриваем 4 случая расположения клеток воды вокруг клетки дома и отметаем варианты где выходит за индексы массива
  66.                 if Wx + 1 <= M - 1 then
  67.                   if W[Wx + 1, Wy] = 1 then
  68.                     num := num + 1;
  69.                 if Wx - 1 >= 0 then
  70.                   if W[Wx - 1, Wy] = 1 then
  71.                     num := num + 1;
  72.                 if Wy + 1 <= N - 1 then
  73.                   if W[Wx, Wy + 1] = 1 then
  74.                     num := num + 1;
  75.                 if Wy - 1 >= 0 then
  76.                   if W[Wx, Wy - 1] = 1 then
  77.                     num := num + 1;
  78.               end;
  79.             end;
  80.           end;
  81.         end;
  82.       end;
  83.     end;
  84.     ans := max(ans, num);
  85.   end;
  86.   writeln(ans);
  87. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement