#include #include #include #include #include #include #include #include enum { unknown, space, wall, }; int field[64][64]; int x = 32, y = 32; int px, py; int d = 0; void printfield() { for(int i = 0; i < 64; ++i) { for(int j = 0; j < 64; ++j) { if( y == i and x == j ) { char t[5] = "RDLU"; printf("%c", t[d]); continue; } char t2[4] = "+ #"; printf("%c", t2[field[i][j]]); } printf("\n"); } } int main() { field[y][x] = space; std::string str; for(;;) { //printfield(); std::getline(std::cin, str); if( str == "Merry Christmas!" ) break; int in = std::stoi(str); // step 1 : end? if( in == 20151224 ) { std::cout << "F" << std::endl; for(;;) { std::getline(std::cin, str); if( str == "Merry Christmas!" ) { break; } } break; } // step 2 : update field int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int nx = x + dx[d], ny = y + dy[d]; for(int i = 0; i < in; ++i) { field[ny][nx] = space; nx += dx[d]; ny += dy[d]; } field[ny][nx] = wall; // step 3 : right check if( field[y+dy[(d+1)%4]][x+dx[(d+1)%4]] == unknown ) { std::cout << "R" << std::endl; d = (d + 1) % 4; continue; } // step 4 : left check if( field[y+dy[(d+3)%4]][x+dx[(d+3)%4]] == unknown ) { std::cout << "L" << std::endl; d = (d + 3) % 4; continue; } if( field[y+dy[(d+2)%4]][x+dx[(d+2)%4]] == unknown ) { std::cout << "L" << std::endl; d = (d + 3) % 4; std::cin >> str; std::cout << "L" << std::endl; d = (d + 3) % 4; continue; } // step 5 move std::vector movable = {}; for(int i = 0; i < 4; ++i) { if( field[y+dy[(d+i)%4]][x+dx[(d+i)%4]] == space and y+dy[(d+i)%4] != py and x+dx[(d+i)%4] != px ) { movable.push_back(i); } } int choice = movable[rand()%movable.size()]; px = x, py = y; if( movable.size() == 1 ) { px = 100; py = 100; } switch( choice ) { case 0 : std::cout << "F" << std::endl; x += dx[d]; y += dy[d]; break; case 1 : std::cout << "R" << std::endl; d = (d + 1) % 4; std::cin >> str; std::cout << "F" << std::endl; x += dx[d]; y += dy[d]; break; case 2 : std::cout << "R" << std::endl; d = (d + 1) % 4; std::cin >> str; std::cout << "R" << std::endl; d = (d + 1) % 4; std::cin >> str; std::cout << "F" << std::endl; x += dx[d]; y += dy[d]; break; case 3 : std::cout << "L" << std::endl; d = (d + 3) % 4; std::cin >> str; std::cout << "F" << std::endl; x += dx[d]; y += dy[d]; break; } } return 0; }