#include #include #include #include using namespace std; const int fieldSize = 16; enum FieldVect { UP, RIGHT, DOWN, LEFT }; struct block { int num = 0; bool move = false; }; void CommandAdd(FieldVect vec,vector *buf,queue> *commandList) { buf->push_back(vec); commandList->push(*buf); buf->pop_back(); } int main() { int field_input[fieldSize]; block field_basic[fieldSize]; block field[fieldSize]; queue> commandList; vector buf; int index = -1; int oldindex = -1; FieldVect gv; bool moved = false; bool complate = false; block box; for (int i = 0; i < fieldSize; i++)field[i].num = field_basic[i].num = (i + 1)% fieldSize; for (int i = 0; i < fieldSize; i++)cin >> field_input[i]; CommandAdd(UP, &buf, &commandList); CommandAdd(LEFT, &buf, &commandList); while (!commandList.empty()) { buf = commandList.front(); commandList.pop(); complate = true; for (int i = 0; i < fieldSize; i++)complate &= field[i].num == field_input[i]; if (!complate) { memcpy(field, field_basic, sizeof(field)); index = fieldSize - 1; moved = true; for (int i = 0; i < buf.size(); i++) { gv = buf[i]; oldindex = index; switch (gv) { case UP: { index += -4; if (index < 0)index = -1; break; } case RIGHT: { if (index % 4 + 1 >= 4) { index = -1; } else { index += 1; } break; } case DOWN: { index += 4; if (index >= fieldSize)index = -1; break; } case LEFT: { if (index % 4 - 1 < 0) { index = -1; } else { index += -1; } break; } default:index = -1; break; } if (index < 0 || index > fieldSize - 1)index = -1; if (index != -1 && !field[index].move) { field[index].move = true; box = field[index]; field[index] = field[oldindex]; field[oldindex] = box; } else { moved = false; } } if (moved) { CommandAdd(UP, &buf, &commandList); CommandAdd(RIGHT, &buf, &commandList); CommandAdd(LEFT, &buf, &commandList); CommandAdd(DOWN, &buf, &commandList); } } } cout << (complate ? "Yes" : "No") << endl; return 0; }