|
|
back to boardDiscussion of Problem 1122. GameShow all messages Hide all messagesMy solution is very ugly Maybe yours is beautiful How nice is your solution? 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. 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. 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 I see, you weren't serious. Sorry. |
|
|