您的位置:首页 > 其它

兰顿蚂蚁

2015-07-28 07:28 387 查看
import java.util.Scanner;

public class 兰顿蚂蚁 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int m=input.nextInt();
int[][] address=new int
[m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
address[i][j]=input.nextInt();
}
}
int x=input.nextInt();
int y=input.nextInt();
String s=input.next();
int k=input.nextInt();
String[] direction={"L","U","R","D"};
int temp=0;
for(;temp<=3;temp++){
if(s.equals(direction[temp]))break;
}
for(int i=0;i<k;i++){
if(address[x][y]==0){
address[x][y]=1;
temp=(temp+3)%4;
if(temp==0)y=y-1;
if(temp==1)x=x-1;
if(temp==2)y=y+1;
if(temp==3)x=x+1;
}
else{
address[x][y]=0;
temp=(temp+1)%4;
if(temp==0)y=y-1;
if(temp==1)x=x-1;
if(temp==2)y=y+1;
if(temp==3)x=x+1;
}
}
System.out.print(x+" "+y);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  蓝桥杯 算法