Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program municip2018n5;
- var
- N, M, i, j, Hx, Hy, x, y, ans, num, Wx, Wy: integer;
- inp: char;
- W, H: array[,] of integer;
- begin
- readln(N);
- readln(M);
- //выделяем память под динамические массивы
- Setlength(W, M, N);
- Setlength(H, M, N);
- //читаем H
- for i := 0 to N - 1 do
- begin
- for j := 0 to M - 1 do
- begin
- read(inp);
- if inp = 'H' then
- H[j, i] := 1
- else
- H[j, i] := 0;
- end;
- readln();
- end;
- //читаем W
- for i := 0 to N - 1 do
- begin
- for j := 0 to M - 1 do
- begin
- read(inp);
- if inp = 'W' then
- W[j, i] := 1
- else
- W[j, i] := 0;
- end;
- readln();
- end;
- //Помещаем воду в (0;0) -> (M;N); Перебираем положение дома по крайней точке слева снизу (-M;-N) -> (M;N)
- for Hx := -M to M + 1 do
- begin
- for Hy := -N to N + 1 do
- begin
- //Получили значение для крайней точки дома - (Hx,Hy);
- //Нужно перебрать все x и y для дома (сравниваем с озером)
- num := 0;
- for x := 0 to M - 1 do
- begin
- for y := 0 to N - 1 do
- begin
- //num считает количество общих ребер у дома и озера
- //рассматриваем клетки где есть дом
- if H[x, y] = 1 then
- begin
- Wx := Hx + x;
- Wy := Hy + y;
- if (Wx >= 0) and (Wx < M) and (Wy >= 0) and (Wy < N) then
- begin
- if W[Wx, Wy] = 1 then
- num := -2147483648 //отметаем случай где вода накладывается на дом
- else
- begin
- // рассматриваем 4 случая расположения клеток воды вокруг клетки дома и отметаем варианты где выходит за индексы массива
- if Wx + 1 <= M - 1 then
- if W[Wx + 1, Wy] = 1 then
- num := num + 1;
- if Wx - 1 >= 0 then
- if W[Wx - 1, Wy] = 1 then
- num := num + 1;
- if Wy + 1 <= N - 1 then
- if W[Wx, Wy + 1] = 1 then
- num := num + 1;
- if Wy - 1 >= 0 then
- if W[Wx, Wy - 1] = 1 then
- num := num + 1;
- end;
- end;
- end;
- end;
- end;
- end;
- ans := max(ans, num);
- end;
- writeln(ans);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement