c语言的编程问题:蟑螂随机漫步

来源:百度知道 编辑:UC知道 时间:2024/09/21 14:32:39
一直醉酒的蟑螂趴在15*15的方格纸的中央方格处,蟑螂一步迈出一个方格,该方格是此蟑螂所在方格周围8个方格中的任意一个,蟑螂无法进行任何思考,随即迈到8个方格的任意一个,求蟑螂何时迈出这张纸?

给你,已经编译运行确认了:
#include<stdio.h>

#include<stdlib.h>
#include<time.h>

//最大步数限制
#define MAX_STEP_ON 65535
#define MAX_X 15
#define MAX_Y 15

//房间的磁砖
unsigned arr[MAX_X][MAX_Y];

//相邻磁砖的位移
const int stepx[]={-1,0,1,1,1,0,-1,-1};
const int stepy[]={1,1,1,0,-1,-1,-1,0};

//记录当前位置
int current[2];

//步数
unsigned stepcount=0;

int check(){
int x,y;
for(x=0;x<MAX_X;x++){
for(y=0;y<MAX_Y;y++){
if(arr[x][y]==0)
return 0;
}
}
return 1;
}

int printinfo(int success){
if(!success){
printf("It's not Complete walk around the room\n");
}
printf("the bug total walk:%d steps\n\n",stepcount);
int x,y;
for(x=0;x<MAX_X;x++){
for(y=0;y<MAX_Y;y++){
if(y==0)
pr