ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1122. Игра

Painful to code
Послано Mahilewets Nikita [BSUIR] 24 сен 2017 12:19
My solution is very ugly
Maybe yours is beautiful
How nice is your solution?
Re: Painful to code
Послано Oleg Baskakov 24 сен 2017 15:30
How ugly can it be? Just need to use three functions: convert board to 2-byte value, unconvert, modify board by making a move at (x, y). And with those, we just do usual BFS, until 0 or 65535 is reached.
Unless of course you're not doing brute force but some smart solution.
Re: Painful to code
Послано Mahilewets Nikita [BSUIR] 24 сен 2017 21:43
That function modifies board
https://ideone.com/w5JRRH
Re: Painful to code
Послано Oleg Baskakov 24 сен 2017 23:00
What? Why? You can't be serious.

I'll try to scribble the concept in pascal...

type TBoard = array[0..3, 0..3] of shortint; //the board
     TMod = array[0..2, 0..2] of shortint;   //the modifier
var md: TMod;
...
procedure ModifyBoard(x, y: shortint; var board: TBoard);
//x, y are coordinates of our move's center
//board links to the board array we're modifying
var i, j: shortint;
begin
    for i:=-1 to +1 do
        for j:=-1 to +1 do
            if (x + i >= 0) and (x + i <= 3) and
               (y + j >= 0) and (y + j <= 3) then begin //out of bounds check
                if md[i + 1, j + 1] > 0 then board[x + i, y + j]:=1 - board[x + i, y + j]; //flipping if spot is marked for that
            end;
end;

I guess not more effecient than your bit operations, but definitely easier to read. You can, like, just convert 2-byte state into a full board and convert it back with separate functions if needed.
Re: Painful to code
Послано Mahilewets Nikita [BSUIR] 25 сен 2017 00:37
Why?
Because I have solved a very similar task
Flip game
I don't like to solve the same task with the same method twice
Re: Painful to code
Послано Oleg Baskakov 25 сен 2017 01:43
I see, you weren't serious. Sorry.