#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU ############################################################ def gs() gets.chomp end def gi() gets.to_i end def gf() gets.to_f end def gss() gs.split end def gis() gss.map(&:to_i) end def gfs() gss.map(&:to_f) end def nmapf(n,f) n.times.map{ __send__ f } end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end def arr2d(h,w,v=0) h.times.map{[v] * w} end def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end def nsum(n) n * (n + 1) / 2 end def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end ############################################################ =begin 最大でも20x20なんで うまくやればTLEなんて起こらないはずなのに 壁伝いだと以下に気をつけるべき ループに捕まると抜け出せない ########## #......... #..####..# #.v#..#..# #..####..# #........# ########## 行き止まりも恐い ########## #.#....... #.#.###### #.#......# #.#.###### #......v.# ########## 下手すると上下左右に単機ループがあるかもしれない ########## #......... #...#....# #.#.v.#..# #........# #...#....# #........# ########## =end UNKNOWN_CELL = 0 WALL_CELL = 1 SPACE_CELL = 2 f = arr2d(60, 60) w = arr2d(60, 60) x = 30 y = 30 dx = 1 dy = 0 f[y][x] = SPACE_CELL def rotr(dx, dy) [-dy, dx] end def rotl(dx, dy) [dy, -dx] end def rcell(f, x, y, dx, dy) rx, ry = rotr(dx, dy) f[y + ry][x + rx] end def lcell(f, x, y, dx, dy) lx, ly = rotl(dx, dy) f[y + ly][x + lx] end t = 0 loop { s = STDIN.gets break if s[0] == "M" if s.size > 2 STDOUT.puts "F" else d = s.to_i if f[y + dy][x + dx] == UNKNOWN_CELL (1..d).each do |i| f[y + dy * i][x + dx * i] = SPACE_CELL end f[y + dy * d.succ][x + dx * d.succ] = WALL_CELL w[y + dy * d.succ][x + dx * d.succ] = WALL_CELL loop { flg = 0 for2p(9..51,9..51) {|i,j| next if f[i][j] != SPACE_CELL next if w[i][j] == WALL_CELL c = 0 [[-1,0],[1,0],[0,-1],[0,1]].each do |ii,jj| c += 1 if f[i + ii][j + jj] == WALL_CELL || w[i + ii][j + jj] == WALL_CELL end if c >= 3 w[i][j] = WALL_CELL flg = 1 end } break if flg == 0 } end nxt = "F" rc = rcell(f, x, y, dx, dy) lc = lcell(f, x, y, dx, dy) if rc == UNKNOWN_CELL nxt = "R" elsif lc == UNKNOWN_CELL nxt = "L" else rw = rcell(w, x, y, dx, dy) lw = lcell(w, x, y, dx, dy) if d > 0 if rw == WALL_CELL && lw == WALL_CELL nxt = "F" elsif rw != WALL_CELL nxt = "RRFFFFFF"[rand(7)] elsif lw != WALL_CELL nxt = "LLFFFFFF"[rand(7)] else nxt = "F" end else if rc == SPACE_CELL && lc == SPACE_CELL && rw != WALL_CELL && lw != WALL_CELL nxt = "LRLRRL"[rand(4)] elsif rc == SPACE_CELL && rw != WALL_CELL nxt = "R" else nxt = "L" end end end if w[y][x] == WALL_CELL nx, ny = dx, dy a = [] 4.times do |i| tx, ty = x, y (1..20).each do tx += nx ty += ny break if f[ty][tx] == WALL_CELL if f[ty][tx] == SPACE_CELL && w[ty][tx] != WALL_CELL a << "FRLB"[i] break end end nx, ny = rotr(nx, ny) end if a.size > 0 nxt = a[0] else nxt = "FRBL"[rand(4)] end end puts nxt case nxt when "F" x += dx y += dy when "R" dx, dy = rotr(dx, dy) when "L" dx, dy = rotl(dx, dy) when "B" x -= dx y -= dy end end STDOUT.flush }