using System; using System.Collections.Generic; public class ShearTheSheep { static int N, C, bx, by; static char[,] grid; static List fx = new List(); static List fy = new List(); static List fv = new List(); static readonly int[] dx = {1,0,-1,0}; static readonly int[] dy = {0,1,0,-1}; static readonly char[] dir = {'R','D','L','U'}; static void readgrid() { fx.Clear(); fy.Clear(); fv.Clear(); for (int y=0; y='a' && ch<='z') { fx.Add(x); fy.Add(y); fv.Add(ch-'a'); } if (ch=='X') { bx = x; by = y; } } } static void makemoves() { for (int i=0;i0) { // go home char move = 'N'; int bestDist = 10000; for (int j=0;j<4;j++) { int nx = fx[i]+dx[j]; int ny = fy[i]+dy[j]; int dist = Math.Abs(bx-nx) + Math.Abs(by-ny); if (dist=0 && nx=0 && ny=0 && nx=0 && ny='A' && grid[nx,ny]<'E'))) { Console.Write(dir[j] + " "); bFound = true; break; } } if (!bFound) Console.Write("N "); } } Console.WriteLine(); Console.Out.Flush(); } static void Main(string[] args) { N = int.Parse(Console.ReadLine()); C = int.Parse(Console.ReadLine()); grid = new char[N,N]; readgrid(); makemoves(); for (int i=0;i<1000;i++) { //read elapsed time int elapsedTime = int.Parse(Console.ReadLine()); readgrid(); makemoves(); } } }