#include #include #include #include #include #include using namespace std; #define N 151 #define T 11 #define K 21 const int Iterations=10; const int maximum=1000000000; const int maxlen=100000; const int L=24; clock_t beg; int n,m,t,k; char arr[N][N]; pair robots[T][K]; string res1; int num=maximum,test; struct newStruct { pair p[K]; int fitness; string ins; }; newStruct tmp[4]; newStruct r[L]; void input() { char c; int i,j; scanf("%d %d",&n,&m); scanf("%c",&c); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) scanf("%c",&arr[i][j]); scanf("%c",&c); } scanf("%d %d",&t,&k); for(i=0;i> q; pair p; int i,j; for(i=1;i<=n;i++) for(j=1;j<=m;j++) used[i][j]=0; q.push(make_pair(x,y)); used[x][y]=1; arrow[x][y]='F'; while(!q.empty()) { p=q.front(); q.pop(); x=p.first; y=p.second; //cout<n || y<=0 || y>m) continue; if(arr[x][y]=='#') continue; if(!used[x+1][y]) { used[x+1][y]=1; arrow[x+1][y]='S'; q.push(make_pair(x+1,y)); } if(!used[x-1][y]) { used[x-1][y]=1; arrow[x-1][y]='N'; q.push(make_pair(x-1,y)); } if(!used[x][y+1]) { used[x][y+1]=1; arrow[x][y+1]='E'; q.push(make_pair(x,y+1)); } if(!used[x][y-1]) { used[x][y-1]=1; arrow[x][y-1]='W'; q.push(make_pair(x,y-1)); } } } pair doInstructions(int x,int y) { pair res2; res2.first=""; res2.second=0; while(arrow[x][y]!='F') { //cout<=maxlen) return maximum; for(i=0;i=maxlen) return maximum; for(i=0;i=maxlen) return maximum; for(i=0;i evolve(pair res2,int test) { int i,j; for(i=0;i improve(pair res2,int test) { int i,j; for(i=0;i solve(int test) { int i,j,x,y; bool done=0; pair p,res2; bfs(robots[test][0].first,robots[test][0].second); for(i=1;i<=n && !done;i++) for(j=1;j<=n && !done;j++) if(used[i][j] && arr[i][j]!='#') { x=i; y=j; done=1; } // cout< p; beg=clock(); freopen("robots.in","r",stdin); freopen("robots.out","w",stdout); input(); p=solve(0); res1=p.first; num=p.second; test=0; for(i=1;i