Смекни!
smekni.com

Решение задачи о кратчайшем маршруте (стр. 3 из 3)

then k[i]:=mas[0,i]+mas[i,j]

else k[i]:=-1;

mas[0,j]:=min;

mas[j,0]:=mas[0,j];

end;

{4}

repeat

l:=true;

for i:=1 to n do

for j:=1 to n do

if (mas[0,j]-mas[0,i]>mas[i,j]) and (mas[i,j]<>-1) then

begin

l:=false;

mas[0,j]:=mas[0,i]+mas[i,j];

end;

until l;

{5}

j:=n;

m:=1;

t:=0;

for i:=1 to n do

result[i]:=-1;

result[1]:=n;

repeat

inc(m);

for i:=1 to j do

begin

if (mas[i,j]<>-1) and (i<>j) and (mas[i,j]=mas[0,j]-mas[0,i])

then

begin

t:=i;

break;

end;

end;

result[m]:=t;

j:=t;

lenth:=m;

until j=1;

calculatedata:=true;

ok;

end;

PROCEDURE stars;

begin

for i:=1 to 500 do

begin

starx[i]:=round(random(640));

stary[i]:=round(random(480));

starc[i]:=round(31-random(16));

end;

end;

PROCEDURE draw_menu;

begin

cleardevice;

for i:=1 to 500 do

putpixel(starx[i],stary[i],starc[i]);

cursor:=1;

lastcursor:=cursor;

for i:=1 to 260 do

begin

setcolor(8);

line(210+i,110,210+i,110);

setcolor(4);

line(200+i,100,200+i,100);

end;

for j:=1 to nline*30+10 do

begin

setcolor(8);

line(210,110+j,470,110+j);

setcolor(4);

line(200,100+j,460,100+j);

end;

setcolor(0);

for j:=1 to nline do

outtextxy(220,110+(j-1)*25,menu[menulevel,j]);

end;

PROCEDURE redraw_menu;

begin

for j:=nline*30+10 downto 1 do

begin

setcolor(0);

line(210,110+j,470,110+j);

line(200,100+j,210,100+j);

setcolor(8);

if j<10 then

begin

setcolor(0);

line(210,100+j,470,100+j);

end

else

line(210,100+j,470,100+j);

end;

for i:=260 downto 0 do

begin

putpixel(210+i,110,0);

putpixel(200+i,100,0);

end;

cleardevice;

end;

PROCEDURE main_menu;

begin

settextstyle(chrus,0,2);

draw_menu;

repeat

setcolor(0);

outtextxy(220,110+(lastcursor-1)*25,menu[menulevel,lastcursor]);

setcolor(7);

outtextxy(220,110+(cursor-1)*25,menu[menulevel,cursor]);

pressed:=readkey;

if pressed=#0 then

begin

pressed:=readkey;

move:=false;

if (pressed=#80) and (cursor=nline) then

begin

lastcursor:=nline; cursor:=1;

move:=true;

end;

if (pressed=#72) and (cursor=1) then

begin

lastcursor:=1;

cursor:=nline;

move:=true;

end;

if (pressed=#80) and (cursor<nline) and not(move) then

begin

lastcursor:=cursor;

inc(cursor);

end;

if (pressed=#72) and (cursor>1) and not(move) then

begin

lastcursor:=cursor;

dec(cursor);

end;

end;

until pressed=#13;

redraw_menu;

if cursor=5 then about_program;

if cursor=4 then about_metod;

if (cursor=1) and (menulevel=3) then keyboard_input;

if (cursor=1) and (menulevel=4) then

begin

closegraph;

halt;

end;

if (cursor=2) and (menulevel=1) and (inputdata=false) then notok;

if (cursor=2) and (menulevel=1) and (inputdata=true) then

begin

count_point_coord;

draw_ways;

output_graph;

end;

if (cursor=2) and (menulevel=0) and (inputdata=true) then calculate;

if (cursor=2) and (menulevel=0) and (inputdata=false) then notok;

if (cursor=1) and (menulevel=2) and (calculatedata=false) then notok;

if (cursor=1) and (menulevel=2) and (calculatedata=true) then

begin

count_point_coord;

draw_ways;

draw_short_way;

output_graph;

end;

if (cursor=2) and (menulevel=2) and (calculatedata=true) then save;

if (cursor=2) and (menulevel=2) and (calculatedata=false) then notok;

if (cursor=2) and (menulevel=3) then notok;

menulevel:=menugo[menulevel,cursor];

nline:=menuof[menulevel];

main_menu;

end;

PROCEDURE welcomescreen;

begin

settextstyle(chrus,0,1);

randomize;

install_firewall;

for i:=0 to messize do

begin

setcolor(4);

outtextxy(10,iii*step+i*30,title[i]);

end;

repeat

fire;

until keypressed;

end;

BEGIN

for i:=0 to 20 do

for j:=0 to 20 do

mas[i,j]:=-1;

stars;

inputdata:=false;

calculatedata:=false;

menulevel:=0;

nline:=menuof[menulevel];

z2:=0;

set_graph_mode;

set_font;

welcomescreen;

closegraph;

z2:=2;

set_graph_mode;

main_menu;

repeat until keypressed;

END.