91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .cpp
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-12-16
  • 語言: C/C++
  • 標(biāo)簽: c++??走迷宮??回溯算法??

資源簡介

最近在leetcode上做到一個運(yùn)用遞歸算法解決的題目。忽然記起大一自學(xué)數(shù)據(jù)結(jié)構(gòu)那段歲月。在此拿出三年前寫的老鼠走迷宮案例來進(jìn)行一個簡單的分析鋪墊,順便附上完整代碼,關(guān)于本資源的博客地址:https://blog.csdn.net/qq_34901049/article/details/94403330

資源截圖

代碼片段和文件信息


#include
#include
#define?max?8 //設(shè)置迷宮有效寬度
using?namespace?std;
int?bx=1by=1; //設(shè)置迷宮起點(diǎn)和終點(diǎn)(左上角為起點(diǎn)右下角為終點(diǎn))
int?fx=8fy=8;
void?white()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
}
void?red()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)FOREGROUND_INTENSITY|FOREGROUND_RED);
}
int?maze[max+2][max+2]=???//制作并賦值二維迷宮數(shù)組???為計(jì)算方便在迷宮外圍加了一層?“墻“(‘0‘表示路?‘1‘表示墻)
{
//0??1??2??3??4??5??6??7??8??9??
{1?1?1?1?1?1?1?1?1?1}//0
{1?0?1?1?1?1?1?1?0?1}//1
{1?1?0?0?0?0?1?1?0?1}//2
{1?1?1?0?1?1?1?1?1?1}//3
{1?1?1?0?1?0?0?0?1?1}//4
{1?1?1?0?0?0?1?1?1?1}//5
{1?1?0?1?1?0?1?1?1?1}//6
{1?1?0?1?1?0?0?0?1?1}//7
{1?1?0?0?1?1?1?1?0?1}//8
{1?1?1?1?1?1?1?1?1?1}?//9
};
typedef?struct?move_type//移動方向位置標(biāo)示(八向)
{
int?x;
int?y;
}Move;
Move?move[8];//創(chuàng)建八個移動方向
void?init_move()//初始化方向進(jìn)位表
{
move[0].x?move[4].x=0;
move[1].x=1?move[2].x=1?move[3].x=1;
move[5].x=-1?move[6].x=-1?move[7].x=-1;

move[2].y=0?move[6].y=0;
move[7].y=1?move[0].y=1?move[1].y=1;
move[3].y=-1?move[4].y=-1?move[5].y=-1;

}
typedef?struct?stack_type//迷宮棧(用于保存行走路線)
{
int?x;
int?y;
int?direction;
struct?stack_type?*next;

}stack1;
stack1?*head=new?stack_type;//創(chuàng)建頭結(jié)點(diǎn)
void?init_stack()//初始化棧
{?
head->next=NULL;
head->x=0;
head->y=0;
head->direction=-1;
}
int?count_stack=0;
void?push_stack(int?xint?yint?direction)//進(jìn)棧
{
stack1?*p1=new?stack_type;
p1->next=head->next;
p1->x=x;
p1->y=y;

p1->direction=direction;
head->next=p1;
count_stack++;

}
void?pop_stack(int?&x1int?&y1int?&direction1)//出棧
{
stack1?*p1=head->next;
x1=p1->x;
y1=p1->y;
direction1=p1->direction;
head->next=p1->next;
delete?p1;
count_stack--;

}
void?trave_stack()
{
stack1?*p=new?stack_type;
p=head->next;
int?n=0;
while(p!=NULL)
{
n++;
if(n==1)
{
cout<<“還原路線(坐標(biāo)(xy)):“< red();
cout<<“終點(diǎn):“;
white();
cout<<“

評論

共有 條評論