日期:2014-05-20  浏览次数:21173 次

迷宫问题?
如下:
1101111110
0101010011
1111111010
1101111111
如何判断能从其中一个1(如左上角)到达另一个1(右下角),并且能记录如何走?
上面1表示可以走,我的问题(10*10)中1处较少。

    int       maze[10][10]={    
                {0,0,0,0,0,0,0,0,0,0},      
                {0,1,1,0,1,1,1,0,1,0},      
                {0,1,1,0,1,1,1,0,1,0},      
                {0,1,1,1,1,0,0,1,1,0},      
                {0,1,0,0,0,1,1,1,1,0},      
                {0,1,1,1,0,1,1,1,1,0},      
                {0,1,0,1,1,1,0,1,1,0},      
                {0,1,0,0,0,1,0,0,1,0},      
                {0,0,1,1,1,1,1,1,1,0},      
                {0,0,0,0,0,0,0,0,0,0},      
        };   /*定义迷宫*/    
最好给个代码?




------解决方案--------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MiGong
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// Required designer variable.
/// </summary>
///

public struct Pos
{
public int x;
public int y;
}

public struct StackItem
{
public int order;
public int dir;
public Pos curPos;
}

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1 ";
this.listBox1.Size = new System.Drawing.Size(536, 340);
this.listBox1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(544, 382);