import java.util.Scanner;
public class Main {
static int x1=0;
static int y1=0;
static int count;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
int [][]a=new int[m][n];
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
a[i][j]=sc.nextInt();
}
}
int x=sc.nextInt();
int y=sc.nextInt();
String s=sc.next();
int k=sc.nextInt();
count=k+1;
move(a,x,y,s);
System.out.println(x1+" "+y1);
}
public static void move(int a[][],int x,int y,String s) {
if(count==0)
return;
count--;
if(count==0) {
x1=x;
y1=y;
}
if(a[x][y]==1) {
a[x][y]=0;
switch(s) {
case "U":move(a,x,y+1,"R");
case "R":move(a,x+1,y,"D");
case "D":move(a,x,y-1,"L");
case "L":move(a,x-1,y,"U");
}
}
else
if(a[x][y]==0) {
a[x][y]=1;
switch(s) {
case "U":move(a,x,y-1,"L");
case "L":move(a,x+1,y,"D");
case "D":move(a,x,y+1,"R");
case "R":move(a,x-1,y,"U");
}
}
}
}
蓝桥杯历届试题——诺顿蚂蚁
最新推荐文章于 2020-03-21 18:38:13 发布