#include #include #include #define startvalue 2012
#define endvalue 2013
#define queuesize (1024*1024) //size of the queue for bfs
#define maxvalue (65535)
typedef enumstate;
typedef enumopera;
typedef struct node*quadtree;
quadtree root,root_rev;
node** existnode;
node** existnode_rev;
node * newnode(int v, node* n,int p, state s)
struct queuenodequeue, nodequeue_rev;
void initqueue()
void enqueue(queue* nodequeue, node * q)
nodequeue->data[nodequeue->tailer] = q;
nodequeue->tailer = (nodequeue->tailer+1)%nodequeue->size;
}node* dequeue(queue* nodequeue)
void queueclear(queue* nodequeue)
node* popstack(queue* nodequeue)
int add(int temp)
int minus(int temp)
int mul(int temp)
int div(int temp)
int (*fun[5])(int) =; //function pointer
int add_rev(int temp)
int minus_rev(int temp)
int mul_rev(int temp)
int div_rev(int temp)
int div2_rev(int temp) //
int (*fun_rev[5])(int) =; //function pointer
//three-dimensional matrice: according to [state], [path], [next operation] return [next state]
state statecompute[3][6][5]=,
, ,
, ,
},, ,
, ,
, }, ,
, ,
, ,
}};node* i***istrevtree(node** existnode, node* node);
void outputresult(node* meet)
while((end=popstack(&nodequeue))!=null)
printf("%d\t%d%c%c=%d\n",++i,end->parent->value,opera[2*end->path],opera[1+2*end->path],end->value);
end = i***istrevtree(existnode_rev,meet);
while(end->parent!=null)
}void outputresult_rev(node* meet)
while((end=popstack(&nodequeue))!=null)
printf("%d\t%d%c%c=%d\n",++i,end->parent->value,opera[2*end->path],opera[1+2*end->path],end->value);
end = meet;
while(end->parent!=null)
}void initpruning()
bool pruning(node** existnode, node* node)
node* i***istrevtree(node** existnode, node* node)
return null;
}void expand(node * node) }}
void expand_rev(node * node) }}
int main()
printf("completion!\n");
return 0;
}
迷宮問題bfs
迷宮問題 採用佇列的廣度優先遍歷 bfs 思想是從乙個頂點v0開始,輻射狀地優先遍歷其周圍較廣的區域 找到的解為最優解 include define m 8 define n 8 define maxsize 1000 typedef struct box typedef struct qutype...
迷宮問題BFS
the code 資料結構迷宮.cpp 定義控制台應用程式的入口點。include stdafx.h include include include include define n 4 定義迷宮為4 4 using namespace std struct pot 為記錄路徑的rec準備,座標 x...
迷宮問題bfs
小明置身於乙個迷宮,請你幫小明找出從起點到終點的最短路程。小明只能向上下左右四個方向移動。輸入包含多組測試資料。輸入的第一行是乙個整數t,表示有t組測試資料。每組輸入的第一行是兩個整數n和m 1 n,m 100 接下來n行,每行輸入m個字元,每個字元表示迷宮中的乙個小方格。字元的含義如下 s 起點 ...