Allen


私信TA

用户名:uq_91397912472

访问量:993

签 名:

呜呜呜再也不敢偷偷写代码了

等  级
排  名 2792
经  验 2068
参赛次数 0
文章发表 9
年  龄 15
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	int maze[500][500];
	int x,y,step;
	string dir;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>maze[i][j];
		}
	}
	cin>>x>>y>>dir>>step;
	set<string>st;//四个方向来表示头的朝向上下左右
//	mp["U"]=0;
//	mp["D"]=0;
//	mp["L"]=0;
//	mp["R"]=0;
	st.insert(dir);
	//若蚂蚁在黑格,右转90度,将该格改为白格,并向前移一格;
	//若蚂蚁在白格,左转90度,将该格改为黑格,并向前移一格。
	while(step--){
		if(maze[x][y]==0){ //0代表白格子 
			maze[x][y]=1;  //1代表黑格子 
			if(st.count("L")){
				x++;//前进 
				st.erase("L");
				st.insert("D");
			}else if(st.count("R")){
				x--; 
				st.erase("R");
				st.insert("U");
			}else if(st.count("U")){
				y--; 
				st.erase("U");
				st.insert("L");
			}else if(st.count("D")){
				y++; 
				st.erase("D");
				st.insert("R");
			}
		}else{
			maze[x][y]=0;
			if(st.count("L")){
				x--;//前进 
				st.erase("L");
				st.insert("U");
			}else if(st.count("R")){
				x++; 
				st.erase("R");
				st.insert("D");
			}else if(st.count("U")){
				y++; 
				st.erase("U");
				st.insert("R");
			}else if(st.count("D")){
				y--; 
				st.erase("D");
				st.insert("L");
			}
		}
	}
	cout<<x<<" "<<y<<endl;
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区