Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {Ww}
- uses sysutils,math;
- const isfile='beard4.map';
- const zzc = 20000;
- const size = 500;
- const maxiter = 5000;
- const lfsmax = 30;
- var ourd,numdest,numsour,ppo:longint;
- var oppp:longint;
- var sourcesx,sourcesy:array[1..10] of longint;
- var destinationsx,destinationsy:array[1..10] of longint;
- var ppp,numt:longint;
- var teee:longint;
- var xto,xfrom,yto,yfrom:longint;
- var ii,jj:longint;
- var sch:char;
- var za,sc:longint;
- var stepiter:longint;
- var onceadd:boolean;
- var ctime:TDateTime;
- var tst:longint;
- var nera,nepp,tera,pp:longint;
- var checked:boolean;
- var endd:boolean;
- var lose:boolean;
- var appended:boolean;
- var bestres:string;
- var mincryst:longint;
- var i,j:longint;
- var reshenie,restemp:widestring;
- var maze:array[1..size,1..size] of char;
- var umaze:array[1..size,1..size] of char;
- var tmaze:array[1..size,1..size] of longint;
- var mazes:array[1..maxiter+3,1..size,1..size] of char;
- var kristall:array[1..maxiter+3] of longint;
- var opened:array[1..maxiter+3] of boolean;
- var changed:array[1..maxiter+3] of boolean;
- var poradok:array[1..maxiter+3] of string;
- var iter:array[1..maxiter+3] of longint;
- var crystalsx:array[1..size*size] of longint;
- var crystalsy:array[1..size*size] of longint;
- var uaternou:array[1..maxiter+3] of longint;
- var uater, flooding, uaterproof:longint;
- var trampo:array[1..maxiter+3,1..10] of longint;
- var leng:array[1..size] of longint;
- var totalcrystall:longint;
- var maxleng:longint;
- var tc:char;
- var ts:string;
- var needtocheck:longint;
- var curx,cury:longint;
- var maxx,maxy:longint;
- var robotx,roboty:longint;
- var exitx,exity:longint;
- var ccx,ccy:longint;
- var male:longint;
- var mara,tmara:longint;
- var ocheredx,ocheredy:array[1..size*size] of longint;
- var ocl,ocr:longint;
- var pix,pjx:longint;
- var finished,empty:boolean;
- var tex,tey,culevel:longint;
- var tcx:char;
- var ishzad,uluzad,xuluzad,ulux,uluy:longint;
- procedure checkteleport(curiter:longint);
- var ppp:longint;
- begin
- {check teleporting}
- for ppp:=1 to 10 do
- begin
- if (robotx=sourcesx[ppp]) and
- (roboty=sourcesy[ppp]) and
- (trampo[curiter,ppp]<>0) then
- begin
- ourd:=trampo[curiter,ppp];
- for oppp:=1 to 10 do
- begin
- if trampo[curiter,oppp]=ourd then
- begin
- trampo[curiter,oppp]:=0;
- end;
- end;
- maze[sourcesx[ourd],sourcesy[ourd]]:=' ';
- maze[destinationsx[ourd],destinationsy[ourd]]:='R';
- robotx:=destinationsx[ourd];
- roboty:=destinationsy[ourd];
- end;
- end;
- end;
- function lfs(nepp:longint):char;
- var blilevel,blix,bliy:longint;
- var tepe:char;
- begin
- blix:=0;
- bliy:=0;
- lfs:='N';
- for pix:=1 to maxx do
- for pjx:=1 to maxy do
- tmaze[pix,pjx]:=-1;
- ishzad:=trunc(sqrt(sqr(robotx-crystalsx[nepp])+sqr(roboty-crystalsy[nepp])));
- uluzad:=ishzad;
- ulux:=0; uluy:=0;
- tmaze[robotx,roboty]:=1;
- {tmaze[crystalsx[nepp],crystalsy[nepp]]:=0;}
- ocl:=1;ocr:=2;
- ocheredx[1]:=robotx;
- ocheredy[1]:=roboty;
- finished:=false;
- empty:=false;
- repeat
- {get next}
- tex:=ocheredx[ocl];
- tey:=ocheredy[ocl];
- inc(ocl);if ocl>ocr then empty:=true;
- if ocl=size*size then ocl:=1;
- if ocr=size*size then ocr:=1;
- if empty=false then
- begin
- culevel:=tmaze[tex,tey];
- if culevel<lfsmax then
- begin
- if (tex<>1) then if (tmaze[tex-1,tey]=-1)
- and ((maze[tex-1,tey]=' ')
- or (maze[tex-1,tey]='.')
- or (maze[tex-1,tey]='\')) then
- begin
- if (tex-1=crystalsx[nepp]) and (tey=crystalsy[nepp]) then
- finished:=true;
- tmaze[tex-1,tey]:=culevel+1;
- ocheredx[ocr]:=tex-1;
- ocheredy[ocr]:=tey;
- xuluzad:=trunc(sqrt(sqr(tex-1-crystalsx[nepp])+sqr(tey-crystalsy[nepp])));
- if xuluzad<uluzad then
- begin
- uluzad:=xuluzad;
- ulux:=tex-1;
- uluy:=tey;
- end;
- if (maze[tex-1,tey]='\') and
- (culevel<blilevel) then begin
- blix:=tex-1; bliy:=tey; blilevel:=culevel; end;
- inc(ocr);if ocr=size*size then ocr:=1;
- end;
- if (tex<>maxx) then if (tmaze[tex+1,tey]=-1)
- and ((maze[tex+1,tey]=' ')
- or (maze[tex+1,tey]='.')
- or (maze[tex+1,tey]='\')) then
- begin
- if (tex+1=crystalsx[nepp]) and (tey=crystalsy[nepp]) then
- finished:=true;
- tmaze[tex+1,tey]:=culevel+1;
- ocheredx[ocr]:=tex+1;
- ocheredy[ocr]:=tey;
- xuluzad:=trunc(sqrt(sqr(tex+1-crystalsx[nepp])+sqr(tey-crystalsy[nepp])));
- if xuluzad<uluzad then
- begin
- uluzad:=xuluzad;
- ulux:=tex+1;
- uluy:=tey;
- end;
- if (maze[tex+1,tey]='\') and
- (culevel<blilevel) then begin
- blix:=tex+1; bliy:=tey; blilevel:=culevel; end;
- inc(ocr);if ocr=size*size then ocr:=1;
- end;
- if (tey<>1) then if (tmaze[tex,tey-1]=-1)
- and ((maze[tex,tey-1]=' ')
- or (maze[tex,tey-1]='.')
- or (maze[tex,tey-1]='\')) then
- begin
- if (tey-1=crystalsy[nepp]) and (tex=crystalsx[nepp]) then
- finished:=true;
- tmaze[tex,tey-1]:=culevel+1;
- ocheredx[ocr]:=tex;
- ocheredy[ocr]:=tey-1;
- xuluzad:=trunc(sqrt(sqr(tex-crystalsx[nepp])+sqr(tey-1-crystalsy[nepp])));
- if xuluzad<uluzad then
- begin
- uluzad:=xuluzad;
- ulux:=tex;
- uluy:=tey-1;
- end;
- if (maze[tex,tey-1]='\') and
- (culevel<blilevel) then begin
- blix:=tex; bliy:=tey-1; blilevel:=culevel; end;
- inc(ocr);if ocr=size*size then ocr:=1;
- end;
- if (tey<>maxy) then if (tmaze[tex,tey+1]=-1)
- and ((maze[tex,tey+1]=' ')
- or (maze[tex,tey+1]='.')
- or (maze[tex,tey+1]='\')) then
- begin
- if (tey+1=crystalsy[nepp]) and (tex=crystalsx[nepp]) then
- finished:=true;
- tmaze[tex,tey+1]:=culevel+1;
- ocheredx[ocr]:=tex;
- ocheredy[ocr]:=tey+1;
- xuluzad:=trunc(sqrt(sqr(tex-crystalsx[nepp])+sqr(tey+1-crystalsy[nepp])));
- if xuluzad<uluzad then
- begin
- uluzad:=xuluzad;
- ulux:=tex;
- uluy:=tey+1;
- end;
- if (maze[tex,tey+1]='\') and
- (culevel<blilevel) then begin
- blix:=tex; bliy:=tey+1; blilevel:=culevel; end;
- inc(ocr);if ocr=size*size then ocr:=1;
- end;
- end;
- end
- else
- begin
- finished:=true;
- if uluzad<ishzad then lfs:='M' else lfs:=' ';
- end;
- until finished;
- if (lfs='N') or (lfs='M') then
- begin
- if lfs='N' then
- begin
- ccx:=crystalsx[nepp];
- ccy:=crystalsy[nepp];
- male:=tmaze[ccx,ccy];
- end;
- if lfs='M' then
- begin
- ccx:=ulux;
- ccy:=uluy;
- male:=tmaze[ccx,ccy];
- end;
- if male>2 then begin
- repeat
- if (ccx<>1) and (tmaze[ccx-1,ccy]=male-1) then
- begin
- dec(ccx);
- dec(male);
- end
- else
- if (ccx<>maxx) and (tmaze[ccx+1,ccy]=male-1) then
- begin
- inc(ccx);
- dec(male);
- end
- else
- if (ccy<>1) and (tmaze[ccx,ccy-1]=male-1) then
- begin
- dec(ccy);
- dec(male);
- end
- else
- if (ccy<>maxy) and (tmaze[ccx,ccy+1]=male-1) then
- begin
- inc(ccy);
- dec(male);
- end;
- until male=2;
- end;
- if ccx=robotx-1 then lfs:='L';
- if ccx=robotx+1 then lfs:='R';
- if ccy=roboty-1 then lfs:='U';
- if ccy=roboty+1 then lfs:='D';
- end;
- if length(reshenie)=132 then
- begin
- teee:=0;
- end;
- teee:=0;
- end;
- function zread(l:integer):longint;
- var xi:longint;
- var xxs:string;
- begin
- xxs:='';
- for xi:=l to length(ts) do
- if (ts[xi]>='0') and (ts[xi]<='9') then xxs:=xxs+ts[xi];
- val(xxs,xi);
- zread:=xi;
- end;
- function movefront(poradok:string;c:char):string;
- var cx,po:longint;
- var tss:string;
- begin
- for cx:=1 to length(poradok) do
- begin
- if poradok[cx]=c then po:=cx;
- end;
- tss:=c;
- for cx:=1 to po-1 do tss:=tss+poradok[cx];
- for cx:=po+1 to length(poradok) do tss:=tss+poradok[cx];
- movefront:=tss;
- end;
- {procedure outres;
- var i,j:longint;
- begin
- writeln;
- for i:=1 to maxy do
- begin
- for j:=1 to maxx do
- begin
- write(maze[j,i]);
- end;
- writeln;
- end;
- end;}
- procedure updatefield(curiter:longint);
- var px,py:longint;
- begin
- for py:=1 to maxy do
- for px:=1 to maxx do
- begin
- umaze[px,py]:=maze[px,py];
- end;
- changed[curiter]:=false;
- for py:=1 to maxy do
- for px:=1 to maxx do
- begin
- if maze[px,py]='*' then
- begin
- if py<>maxy then
- begin
- if maze[px,py+1]=' ' then
- begin
- umaze[px,py]:=' ';
- umaze[px,py+1]:='*';
- changed[curiter]:=true;
- end;
- end;
- if (py<>maxy) and (px<>maxx) then
- begin
- if (maze[px,py+1]='*') or
- (maze[px,py+1]='\') then
- begin
- if (maze[px+1,py]=' ') and
- (maze[px+1,py+1]=' ') then
- begin
- umaze[px,py]:=' ';
- umaze[px+1,py+1]:='*';
- changed[curiter]:=true;
- end
- else
- if (maze[px-1,py]=' ') and
- (maze[px-1,py+1]=' ') and
- (maze[px,py+1]='*') then
- begin
- umaze[px,py]:=' ';
- umaze[px-1,py+1]:='*';
- changed[curiter]:=true;
- end;
- end;
- end;
- end;
- end;
- if changed[curiter] then
- begin
- if (roboty>1) and
- (maze[robotx,roboty-1]<>'*') and (umaze[robotx,roboty-1]='*') then
- lose:=true;
- for py:=1 to maxy do
- for px:=1 to maxx do
- begin
- maze[px,py]:=umaze[px,py];
- end;
- end;
- end;
- procedure generateanswer(iteration:longint);
- var curiter:longint;
- var px,py:longint;
- var needtocheck:longint;
- begin
- if TimeStamptoMSecs(DateTimeToTimestamp(now))-ctime<zzc then begin
- curiter:=iteration+1;
- if (curiter<>1) then
- for px:=1 to 10 do
- trampo[curiter,px]:=trampo[curiter-1,px];
- if (curiter<>1) then
- begin
- if uater+floor(curiter/flooding)>=maxy-roboty then
- uaternou[curiter]:=uaternou[curiter-1]+1 else
- uaternou[curiter]:=0;
- end;
- if uaternou[curiter]>=uaterproof then
- begin
- lose:=true;
- end;
- if (curiter<>1) and (lose=false) then
- begin
- if kristall[curiter-1]<mincryst then
- begin
- bestres:=reshenie;
- mincryst:=kristall[curiter-1];
- {writeln('New best: ',bestres);}
- end;
- if (kristall[curiter-1]=mincryst) and (length(reshenie)<length(bestres)) then
- begin
- bestres:=reshenie;
- mincryst:=kristall[curiter-1];
- {writeln('New best: ',bestres);}
- end;
- end;
- {outres;
- writeln(reshenie);
- if curiter<>1 then writeln(kristall[curiter-1]);}
- {readln;}
- if curiter>2 then
- begin
- if kristall[curiter-2]>kristall[curiter-1] then
- begin
- iter[curiter]:=iter[curiter-1]+stepiter;
- if iter[curiter]>maxiter-10 then
- begin
- iter[curiter]:=maxiter-10;
- end;
- end
- else
- iter[curiter]:=iter[curiter-1];
- end;
- if curiter<iter[curiter] then
- if lose<>true then
- begin
- lose:=false;
- for py:=1 to maxy do
- for px:=1 to maxx do
- begin
- mazes[curiter,px,py]:=maze[px,py];
- end;
- {check last iter}
- if curiter<>1 then
- begin
- if mazes[curiter-1,robotx,roboty]='\' then
- kristall[curiter]:=kristall[curiter-1]-1 else
- kristall[curiter]:=kristall[curiter-1];
- end
- else kristall[curiter]:=totalcrystall;
- {may _e at exit?}
- if curiter<>1 then
- begin
- if kristall[curiter]=0 then
- begin
- if (exitx=robotx) and (exity=roboty-1) then
- begin
- reshenie:=reshenie+'U';
- bestres:=reshenie;
- endd:=true;
- end;
- if (exitx=robotx) and (exity=roboty+1) then
- begin
- reshenie:=reshenie+'D';
- bestres:=reshenie;
- endd:=true;
- end;
- if (exitx=robotx-1) and (exity=roboty) then
- begin
- reshenie:=reshenie+'L';
- bestres:=reshenie;
- endd:=true;
- end;
- if (exitx=robotx+1) and (exity=roboty) then
- begin
- reshenie:=reshenie+'R';
- bestres:=reshenie;
- endd:=true;
- end;
- end;
- end;
- if endd then exit;
- poradok[curiter]:='UDLRW';
- {optimize movements}
- {not repeat}
- for za:=1 to 4 do
- begin
- sc:=random(4)+1;
- sch:=poradok[curiter][sc];
- poradok[curiter]:=movefront(poradok[curiter],sch);
- end;
- {find near-crystals}
- nera:=100000;
- mara:=100000;
- nepp:=0;
- for pp:=1 to totalcrystall do
- begin
- if maze[crystalsx[pp],crystalsy[pp]]='\' then
- {do not _ant crystal and rock above}
- if (crystalsy[pp]>=roboty) or (crystalsy[pp]=1) or
- ((crystalsy[pp]<>1) and
- (maze[crystalsx[pp],crystalsy[pp]-1]<>'*')) then
- begin
- if crystalsx[pp]>robotx then
- begin
- xfrom:=robotx;
- xto:=crystalsx[pp];
- end
- else
- begin
- xfrom:=crystalsx[pp];
- xto:=robotx;
- end;
- if crystalsy[pp]>roboty then
- begin
- yfrom:=roboty;
- yto:=crystalsy[pp];
- end
- else
- begin
- yfrom:=crystalsy[pp];
- yto:=roboty;
- end;
- tera:=0;
- for ii:=xfrom to xto do
- for jj:=yfrom to yto do
- begin
- if (maze[ii,jj]='#') or
- (maze[ii,jj]='*') then inc (tera);
- end;
- if tera<nera then
- begin
- mara:=trunc(sqrt(sqr(robotx-crystalsx[pp])+sqr(roboty-crystalsy[pp])));
- nera:=tera;
- nepp:=pp;
- end
- else
- if tera=nera then
- begin
- tmara:=trunc(sqrt(sqr(robotx-crystalsx[pp])+sqr(roboty-crystalsy[pp])));
- if tmara<mara then
- begin
- mara:=tmara;
- nepp:=pp;
- end;
- end;
- end;
- end;
- if nepp<>0 then
- begin
- tcx:=lfs(nepp);
- if (tcx<>' ') and (uater=0) and (flooding=100000) then
- poradok[curiter]:=movefront(poradok[curiter],tcx)
- else begin
- if crystalsx[nepp]<robotx then
- poradok[curiter]:=movefront(poradok[curiter],'L');
- if crystalsx[nepp]>robotx then
- poradok[curiter]:=movefront(poradok[curiter],'R');
- if crystalsy[nepp]<roboty then
- poradok[curiter]:=movefront(poradok[curiter],'U');
- if crystalsy[nepp]>roboty then
- poradok[curiter]:=movefront(poradok[curiter],'D');
- end;
- end;
- {nearest crystals}
- if (robotx<>1) and (maze[robotx-1,roboty]='\') then
- poradok[curiter]:=movefront(poradok[curiter],'L');
- if (robotx<>maxx) and (maze[robotx+1,roboty]='\') then
- poradok[curiter]:=movefront(poradok[curiter],'R');
- if (roboty<>1) and (maze[robotx,roboty-1]='\') then
- poradok[curiter]:=movefront(poradok[curiter],'U');
- if (roboty<>maxy) and (maze[robotx,roboty+1]='\') then
- poradok[curiter]:=movefront(poradok[curiter],'D');
- {if need to exit}
- if kristall[curiter]=0 then
- begin
- if exitx<robotx then
- poradok[curiter]:=movefront(poradok[curiter],'L');
- if exitx>robotx then
- poradok[curiter]:=movefront(poradok[curiter],'R');
- if exity<roboty then
- poradok[curiter]:=movefront(poradok[curiter],'U');
- if exity>roboty then
- poradok[curiter]:=movefront(poradok[curiter],'D');
- end;
- for needtocheck:=1 to 5 do
- begin
- {up check}
- if (roboty<>1) and (poradok[curiter][needtocheck]='U') then
- if (maze[robotx,roboty-1]=' ') or
- (maze[robotx,roboty-1]='.') or
- (maze[robotx,roboty-1]='\') {or open lambda lift}
- then begin
- maze[robotx,roboty]:=' ';
- dec(roboty);
- maze[robotx,roboty]:='R';
- checkteleport(curiter);
- updatefield(curiter);
- reshenie:=reshenie+'U';
- generateanswer(curiter);
- end;
- {do_n check}
- if (roboty<>maxy) and (poradok[curiter][needtocheck]='D') then
- if (maze[robotx,roboty+1]=' ') or
- (maze[robotx,roboty+1]='.') or
- (maze[robotx,roboty+1]='\') {or open lambda lift}
- then begin
- maze[robotx,roboty]:=' ';
- inc(roboty);
- maze[robotx,roboty]:='R';
- checkteleport(curiter);
- updatefield(curiter);
- reshenie:=reshenie+'D';
- generateanswer(curiter);
- end;
- {left check}
- if (robotx<>1) and (poradok[curiter][needtocheck]='L') then
- if (maze[robotx-1,roboty]=' ') or
- (maze[robotx-1,roboty]='.') or
- (maze[robotx-1,roboty]='\') {or open lambda lift}
- then begin
- maze[robotx,roboty]:=' ';
- dec(robotx);
- maze[robotx,roboty]:='R';
- checkteleport(curiter);
- updatefield(curiter);
- reshenie:=reshenie+'L';
- generateanswer(curiter);
- end
- else
- if (robotx<>2) and (maze[robotx-1,roboty]='*')
- and (poradok[curiter][needtocheck]='L')
- and (maze[robotx-2,roboty]=' ') then
- begin
- maze[robotx,roboty]:=' ';
- dec(robotx);
- maze[robotx,roboty]:='R';
- maze[robotx-1,roboty]:='*';
- updatefield(curiter);
- reshenie:=reshenie+'L';
- generateanswer(curiter);
- end;
- {right check}
- if (robotx<>maxx) and (poradok[curiter][needtocheck]='R') then
- if (maze[robotx+1,roboty]=' ') or
- (maze[robotx+1,roboty]='.') or
- (maze[robotx+1,roboty]='\') {or open lambda lift}
- then begin
- maze[robotx,roboty]:=' ';
- inc(robotx);
- maze[robotx,roboty]:='R';
- checkteleport(curiter);
- updatefield(curiter);
- reshenie:=reshenie+'R';
- generateanswer(curiter);
- end
- else
- if (robotx<>maxx-1) and (maze[robotx+1,roboty]='*')
- and (poradok[curiter][needtocheck]='R')
- and (maze[robotx+2,roboty]=' ') then
- begin
- maze[robotx,roboty]:=' ';
- inc(robotx);
- maze[robotx,roboty]:='R';
- maze[robotx+1,roboty]:='*';
- updatefield(curiter);
- reshenie:=reshenie+'R';
- generateanswer(curiter);
- end;
- {nothing check}
- if (poradok[curiter][needtocheck]='W') then
- begin
- updatefield(curiter);
- if changed[curiter] then
- begin
- reshenie:=reshenie+'W';
- generateanswer(curiter);
- end;
- end;
- end;
- end;
- begin
- if curiter<>1 then
- begin
- for py:=1 to maxy do
- for px:=1 to maxx do
- begin
- maze[px,py]:=mazes[curiter-1,px,py];
- end;
- restemp:='';
- for px:=1 to length(reshenie)-1 do
- begin
- restemp:=restemp+reshenie[px];
- end;
- {REVERT LAST MOVE}
- if reshenie[length(reshenie)]='L' then inc(robotx);
- if reshenie[length(reshenie)]='R' then dec(robotx);
- if reshenie[length(reshenie)]='U' then inc(roboty);
- if reshenie[length(reshenie)]='D' then dec(roboty);
- reshenie:=restemp;
- {writeln('Oops, reverting');}
- {readln;}
- end;
- {else writeln('All variants checked');}
- end;
- lose:=false;
- end;
- end;
- begin
- ctime:=TimeStamptoMSecs(DateTimeToTimestamp(now));
- lose:=false;
- uater:=0;
- flooding:=0;
- uaterproof:=10;
- endd:=false;
- bestres:='';
- curx:=1;cury:=1;
- maxleng:=1;
- totalcrystall:=0;
- for i:=1 to size do leng[i]:=1;
- appended:=false;
- onceadd:=false;
- while (not EOF) and (not(appended)) do
- begin
- readln(ts);
- if length(ts)<>0 then begin
- for i:=1 to length(ts) do
- begin
- if (ts[i]='!') then ts[i]:=' ';
- if (ts[i]='W') then ts[i]:='#';
- if (ts[i]='@') then ts[i]:='*';
- maze[curx,cury]:=ts[i];
- if ts[i]='\' then
- begin
- inc(totalcrystall);
- crystalsx[totalcrystall]:=curx;
- crystalsy[totalcrystall]:=cury;
- end;
- if ts[i]='R' then
- begin
- robotx:=curx;
- roboty:=cury;
- end;
- if ts[i]='L' then
- begin
- exitx:=curx;
- exity:=cury;
- end;
- inc(curx);
- inc(leng[cury]);
- if curx>maxleng then maxleng:=curx;
- end;
- end else appended:=true;
- dec(leng[cury]);
- curx:=1;
- inc(cury);
- end;
- if appended then
- begin
- for ppo:=1 to 9 do trampo[1,ppo]:=0;
- while (not EOF) do
- begin
- readln(ts);
- if ts[6]=' ' then uater:=zread(7);
- if (ts[9]=' ') and (ts[4]='o') then flooding:=zread(10);
- if (ts[11]=' ') and (ts[4]='e') then uaterproof:=zread(12);
- if (ts[1]='T') and (ts[2]='r') then
- begin
- numsour:=ord(ts[12])-ord('A')+1;
- val(ts[22],numdest);
- trampo[1,numsour]:=numdest;
- end;
- end;
- end;
- uaternou[1]:=0;
- if flooding=0 then flooding:=100000;
- mincryst:=totalcrystall;
- {write('SIZEX=',maxleng,' SIZEY=',cury);}
- dec(cury);
- dec(maxleng);
- for i:=1 to cury do
- begin
- for j:=leng[i]+1 to maxleng do
- begin
- maze[j,i]:=' ';
- end;
- end;
- {writeln;
- for i:=1 to cury do
- begin
- for j:=1 to maxleng do
- begin
- write(maze[j,i]);
- end;
- writeln;
- end;}
- maxx:=maxleng;
- maxy:=cury;
- for i:=1 to maxx do
- for j:=1 to maxy do
- begin
- if (maze[i,j]>='A') and
- (maze[i,j]<='I') then
- begin
- numt:=ord(maze[i,j])-ord('A')+1;
- sourcesx[numt]:=i;
- sourcesy[numt]:=j;
- maze[i,j]:='.';
- end;
- if (maze[i,j]>='1') and
- (maze[i,j]<='9') then
- begin
- numt:=ord(maze[i,j])-ord('1')+1;
- destinationsx[numt]:=i;
- destinationsy[numt]:=j;
- maze[i,j]:='#';
- end;
- end;
- stepiter:=trunc(sqrt(sqr(maxx)+sqr(maxy)));
- iter[1]:=stepiter;
- iter[2]:=stepiter;
- reshenie:='';
- generateanswer(0);
- reshenie:=bestres;
- writeln(bestres);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement