#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void minDist(const vector& plane, char empty, int y0, int x0, vector >& dist) { int dy[] = {0, 0, -1, 1}; int dx[] = {-1, 1, 0, 0}; int h = plane.size(); int w = plane[0].size(); dist.assign(h, vector(w, -1)); queue > q; q.push(make_pair(y0, x0)); dist[y0][x0] = 0; int n = 1; while(!q.empty()){ queue > q1; while(!q.empty()){ int y = q.front().first; int x = q.front().second; q.pop(); for(int i=0; i<4; ++i){ int y1 = y + dy[i]; int x1 = x + dx[i]; if(0 <= y1 && y1 < h && 0 <= x1 && x1 < w && plane[y1][x1] == empty && dist[y1][x1] == -1){ q1.push(make_pair(y1, x1)); dist[y1][x1] = n; } } } ++ n; q = q1; } } const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; int main() { int y = 25; int x = 25; int d = 0; vector grid(50, string(50, '?')); grid[y][x] = '.'; queue > q; vector > dist; for(;;){ int a; if(!(cin >> a)) ;//return 0; int y2 = y + dy[d]; int x2 = x + dx[d]; if(grid[y2][x2] == '?'){ if(a == 0){ grid[y2][x2] = '#'; } else{ grid[y2][x2] = '.'; q.push(make_pair(y2, x2)); } } bool isTurn = false; for(int i=0; i<4; ++i){ int y3 = y + dy[i]; int x3 = x + dx[i]; if(grid[y3][x3] == '?') isTurn = true; } if(isTurn){ cout << 'R' << endl; d = (d + 1) % 4; continue; } if(q.front() == make_pair(y, x)) q.pop(); int ty = q.front().first; int tx = q.front().second; if(dist.empty() || dist[ty][tx] != 0) minDist(grid, '.', ty, tx, dist); if(dist[y2][x2] != -1 && dist[y2][x2] < dist[y][x]){ cout << 'F' << endl; y = y2; x = x2; } else{ cout << 'R' << endl; d = (d + 1) % 4; } } }