解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class A1429 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int [][]arr= new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j]=sc.nextInt();
}
}
int x =sc.nextInt();
int y =sc.nextInt();
String s = sc.next();
int k = sc.nextInt();
int a = 0;
switch (s) {
case "U":a=1000;
break;
case "R":a=1001;
break;
case "D":a=1002;
break;
case "L":a=1003;
break;
default:
break;
}
for (int i = 0; i < k; i++) {
if(arr[x][y]==1) {
a++;
arr[x][y]=0;
}else {
a--;
arr[x][y]=1;
}
switch (a%4) {
case 0:
x--;
break;
case 1:
y++;
break;
case 2:
x++;
break;
case 3:
y--;
break;
default:
break;
}
}
System.out.println(x+" "+y);
}
}
0.0分
0 人评分