Maze path III (shortest path)

Source: Internet
Author: User
Tags int size

The set of shortest paths from the entrance of the maze to each point is considered as a tree. Traverse with breadth
To find the shortest path of the exit. The algorithm idea of this program comes from finding a point in the figure.
Dijkstra algorithm for the shortest path to the remaining points.

/* Maze path III (shortest path )*/
/* Define stramaze. C */
/* 2003-8-26 */
# Include <stdlib. h>
# Include <time. h>
# Include <math. h>
# Include <stdio. h>
# Include <graphics. h>
# Define N 22
# Define M 22
Int bg [M] [N];
Int aa [M] [N];
Struct pace {
Int pre;
Int x;
Int y;
Int ri;
Int rj;
} Road [M * N];
Struct pace bestroad [M * N];


Void makebg (int, int );
Void drawbg (int [] [], int );
Void drawman (int, int, int );
Void rect (int, int );

Void main () {/* main () start */
Int step = 20;
Int len = 10;
Int size = 20;
Int x = 0, y = 0;
Int I = 0, j = 0;
Int gdriver = DETECT, gmode;
Char ch;
Int direc;
Int routelen = 0;
Int dj [] = {-1, 1, 0, 0 };
Int di [] = {0, 0,-1, 1 };
Int begin;
Int end;
Int k;
Int t;
Int num;
Int suc;
Int cnt;
Int x0;
Int y0;
Int le;
Int tmp;
Makebg (M, N );
/* Registerbgidriver (EGAVGA_driver );
Initgraph (& gdriver, & gmode, "c: \ turboc2 ");*/
Initgraph (& gdriver, & gmode, "c: \ tc20 \ bgi ");
Cleardevice ();
Setwritemode (XOR_PUT );
Settextstyle (1, 0, 3 );
Setcolor (GREEN );
Outtextxy (100,180, "dijkstra maze ");
Setcolor (BLUE );
Setfillstyle (LINE_FILL, BLUE );

/* Drawbg (bg, M, N, size, 0, 0 );*/
Drawbg (aa, M, N, size, 0, 0 );
Setcolor (WHITE );
X + = len; y + = len;
Drawman (x, y, len );
X0 = x; y0 = y;
/* Computer Control */
I = j = 0;
Aa [0] [0] = 1;
Begin = 0;
End = 0;
Road [0]. ri = 0;
Road [0]. rj = 0;
Road [0]. x = x0;
Road [0]. y = y0;
Road [0]. pre =-1;
Le = 1;
Suc = 0;
While (! Suc ){
Cnt = 0;
Le ++;
For (k = begin; k <= end; k ++ ){
For (t = 0; t <4; t ++ ){
X = road [k]. x + dj [t] * step;
Y = road [k]. y + di [t] * step;
I = road [k]. ri + di [t];
J = road [k]. rj + dj [t];
If (I <M & I> = 0 & j <N & j></

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.