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 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0


(感觉是search的问题 但找不出问题)

#include
#include
int V=0;

int xnum;
int ynum;
int a[100][100];

typedef struct
{
int x;
int y;
}NODE;
typedef struct
{
NODE nownode;
NODE prenode;
int dir;
}GRID;
NODE start;
NODE end;
GRID grid;

void Init()
{

FILE *fp;fp=fopen(""mice.txt""r"");fscanf(fp%d%d%d%d%d%d""&xnum&ynum&start.x&start.y&end.x&end.y);//24 24 1 1 24 1int ij;for(j=0;j<=ynum+1;j++)    for(i=0;i<=xnum+1;i++)        a[j][i]=1;for(j=1;j<=ynum;j++)    for(i=1;i<=xnum;i++)        fscanf(fp%d""&a[j][i]);//grid.nownode.x =start.x;//grid.nownode.y=start.y;       grid.nownode=start;fclose(fp);

}

void search(int xint y){

if((x==24)&&(y==1))V=1;else{    a[x][y]=1;    if((V==0)&&(a[x][y+1]==0)) //向右查找----------v==0 可避免在V==1时的不必要搜索 第一个if里的可略       search(xy+1);    if((V==0)&&(a[x+1][y]==0))//向下查找      search(x+1y);    if((V==0)&&(a[x][y-1]==0)) //向左查找      search(xy-1);    if((V==0)&&(a[x-1][y]==0)) //向上查找      search(x-1y); }   a[x][y]=0;if(V=1)a[x][y]=2;

}

int main()
{
int xy;
Init();
x=grid.nownode.x;
y=grid.nownode.y;
printf(""%d %dn""start.xstart.y);
printf(""%d %d %d n""a[24][1]a[24][0]a[25][1]);
printf(""%d n""V);
search(xy);

for(int i=0;i<=xnum+1;i++) 

{
for(int j=0;j<=ynum+1;j++)
printf(""%d""a[i][j]);
printf(""n"");
}

scanf(""%d""&x);return 0;}

解决方案

search函数里,

 if(V=1)

应该是双等号吧

 if(V==1)
时间: 2024-08-29 03:02:33

c语言-C 的走迷宫问题 实在找不出问题所在了。。。的相关文章

panel-Extj报错 小弟实在找不出问题 特请大神相助

问题描述 Extj报错 小弟实在找不出问题 特请大神相助 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/

c语言走迷宫问题,输不出结果。。。

问题描述 c语言走迷宫问题,输不出结果... #include void print (int map[][10]); //打印迷宫 void walk (int map[][10], int x, int y); //走迷宫 void push (int x, int *stack); //进栈 void delet (); //出栈 int stackx[100]; //用来存放每一步的x值 int stacky[100]; //每一步的y值 int size = 0; //一共已经走的步数

基于C语言实现简单的走迷宫游戏_C 语言

本文实例讲述了C语言实现简单的走迷宫游戏的方法,代码完整,便于读者理解. 学数据结构时用"栈"写的一个走迷宫程序,实际上用到双向队列,方便在运行完毕后输出经过的点. #include <cstdio> #include <deque> #include <windows.h> using namespace std; class node { public: int x,y; int lastOpt; }; deque<node> sta

c语言 char输出问题,实在找不出来问题

问题描述 c语言 char输出问题,实在找不出来问题 #include #define N 3 struct Student{ int number; int age; char sex; char name[20]; float english; float math; float computer; float aver; }; void main(){ struct Student stu[N]; struct Student *p; p=stu; void input(struct St

走迷宫C#版(一)

//迷宫类相关 using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Collections; namespace MazeDemo{ /// <summary> /// 迷宫类 /// </summary> public class CMaze { bool[,] mg; //地图格子 Stack stack; //堆栈 Point in_p; //入口点 Point out_p

java算法-关于Java的走迷宫问题

问题描述 关于Java的走迷宫问题 题目是这样的: 用户输入一个值,生成一个n*n的矩阵,然后每个符号之间用空格隔开,要求从A到B,如果当前位置的坐标是"+"那么下一个坐标则必须为"-",找出最短的路径的步数 我的代码是把所有的情况写出来,但是出错了,请各位大神看看哪里有问题 import java.util.ArrayList; import java.util.Scanner; public class Main { //矩阵的大小 static int n;

c语言-请问这句话如何编写成C语言代码?(逻辑关系实在搞不懂)

问题描述 请问这句话如何编写成C语言代码?(逻辑关系实在搞不懂) 当电压大于5时,开关断开:直到电压小于3时,开关闭合:在这期间,开关保持断开. 开关闭合后,直到电压大于5,开关断开:在这期间,开关保持闭合. ps:我试着用if ?elseif语句,发现最后一点怎么也满足不了,请各位大神帮忙解答,谢谢! 解决方案 我说了有3个变量 v>5 s v 000 001 010 ... 你排列下去,因为v>5 v<3不同时存在,可以去掉 剩下的你可以用卡诺图化简得到表达式. 解决方案二: 首先,

队列 bfs 迷宫-用bfs走迷宫 队列是自己模拟的

问题描述 用bfs走迷宫 队列是自己模拟的 迷宫问题: 给定一个大小为N*M的迷宫,迷宫由通道和墙壁组成('#','.','S','G'分别表示墙.通道.起点和终点),每一步可以向邻接的上下左右四个方向移动.请给出从起点到终点所需的最小步数.假定起点一定可以到达终点. 没使用STL 我自己模拟队列运行 怎么运行都崩溃 源码 #include<iostream> #include<queue> using namespace std; struct point { int x; in

【重磅】Nature子刊 | 增强学习强化,混合脑生化鼠“走迷宫”能力大幅提升

神经科学和计算机科学的发展加强了大脑和机器之间的融合,现在可以用机械的方式对生物的感觉.记忆和运动机能进行增强或修复,科学家也做出了动物机器人和嵌入生物大脑的认知机器人.诸如此类的生物智能与人工智能相结合,使人不禁思考:这样的混合系统是否比单独的生物系统更加智能? 为了解决这个问题,浙江大学吴朝晖课题组的研究人员率先进行了这样的实验,他们使用采用了机器学习规则的计算系统增强小鼠的大脑,然后观察这样的混合系统是否在学习走迷宫的任务中具有更强的学习能力. 论文摘要:混合脑机系统的迷宫学习 摘要 推动