UDP广播协议叫吃饭


私信TA

用户名:Mustenaka

访问量:134720

签 名:

个人博客www.mustenaka.cn

等  级
排  名 12
经  验 23710
参赛次数 8
文章发表 196
年  龄 3
在职情况 学生
学  校 Sky_box
专  业 NE

  自我简介:

欢迎光临我的博客www.mustenaka.cn,Python,C#,U3D,C/C++开发合作可以找我

解题思路:
    没啥好说的,根据行为来设计函数,然后调用K次就可以了。

    我觉得这一题可以作为游戏设计入门的编程练习题。
参考代码:

写的比较多,但是思路清晰

#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
int mmp[maxn][maxn];//0表示白格,1表示黑格
int m,n;	//地图长度 m行,n列
int x,y;	//蚂蚁位置
char way;	//蚂蚁方向
int k; 		//蚂蚁得步数

char change(int color) {
	if(color==0&&way=='U'||color==1&&way=='D') {
		way='R';
	} else if(color==0&&way=='D'||color==1&&way=='U') {
		way='L';
	} else if(color==0&&way=='L'||color==1&&way=='R') {
		way='U';
	} else if(color==0&&way=='R'||color==1&&way=='L') {
		way='D';
	}

}
void change_color() {
	if(mmp[x][y]==1) {
		mmp[x][y]=0;
	} else if(mmp[x][y]==0) {
		mmp[x][y]=1;
	}
}
void move() {
	if(way=='U') {
		x--;
	} else if(way=='D') {
		x++;
	} else if(way=='L') {
		y--;
	} else if(way=='R') {
		y++;
	}
}
int main() {
	hh;
	while(cin>>m>>n) {
		memset(mmp,-1,sizeof(mmp));
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				cin>>mmp[i][j];
			}
		}
		cin>>x>>y>>way>>k;
		while(k--) {
			change_color();
			change(mmp[x][y]);
			move();
		}
		cout<<x<<' '<<y<<endl;
	}
	return 0;
}


 

0.0分

0 人评分

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

编程语言转换

万能编程问答

代码解释器

  评论区