.


:




:

































 

 

 

 


221.221. ( 1993 ) .




: , , : , , . . .

.

? , 10 10 . 10 10, 12 12, . , . , mypole[1..10,1..10] mypole[0..11,0..11]. , :

, 0;

, 1;

, 2.

, . , . 10, 1. 䳿 , .

, , . , , , , . , .

program morboj;

uses dos, crt,graph;

label mmm;

var gd,gm,i,j,l,i1,j1: integer;

ch: char;

bul: boolean;

mypole, ibmpole: array[0..11,0..11] of byte; { 12 12 }

mykor, ibmkor: integer;

k, kk: integer;

st: string;

xod: integer;

{ i }

procedure och;

begin

repeat ch:=readkey until not keypressed;

end;

procedure wokrug;

var i: integer;

begin

for i:=0 to 11 do

begin

mypole[i,0]:=2; ibmpole[i,0]:=2;

mypole[i,11]:=2; ibmpole[i,11]:=2;

mypole[0,i]:=2; ibmpole[0,i]:=2;

mypole[11,i]:=2; ibmpole[11,i]:=2;

end;

end;

procedure ibmkorabel; { }

var

flag1: boolean;

begin

kk:= 10;

while kk <> 0 do

begin

flag1:= true;

i:= 1 + round(random(10));

j:= 1 + round(random(10));

for i1:= i-1 to i+1 do

for j1:= j-1 to j+1 do

if ibmpole[i1,j1] <> 0 then flag1:= false;

if flag1 = true then

begin

ibmpole[i,j]:= 1;

dec(kk);

end;

end;

wokrug;

end;

procedure korabel; { }

var i1,j1: integer;

flag1: boolean;

begin

flag1:= true;

for i1:= i-1 to i+1 do

for j1:= j-1 to j+1 do

if getpixel(15+i1*10,15+j1*10)<>0 then flag1:= false;

if flag1 = true then

begin

Setcolor(5);

Setfillstyle(1,5);

bar(10+10*i,10+10*j,20+10*i,20+10*j);

mypole[i,j]:=1; { }

dec(k);

end;

end;

procedure wistrel; { }

var i1,j1: integer;

begin

if ibmpole[i,j] = 1 then

begin

ibmpole[i,j]:=2;

line(190+10*i,10+10*j,200+10*i,20+10*j);

line(190+10*i,20+10*j,200+10*i,10+10*j);

for i1:=i-1 to i+1 do

for j1:=j-1 to j+1 do

if ibmpole[i1,j1] = 0 then putpixel(195+10*i1,15+10*j1,1);

dec(ibmkor);

end

else

begin

putpixel(195+10*i,15+10*j,1);

xod:= 0;

end

end;

procedure myxod;

begin

repeat

Setcolor(2);Rectangle(190+10*i,10+10*j,200+10*i,20+10*j);

ch:= readkey;

Setcolor(1);Rectangle(190+10*i,10+10*j,200+10*i,20+10*j);

case ch of

{ } #75: dec(i);

{ } #77: inc(i);

{ } #72: dec(j);

{ } #80: inc(j);

{ } #32: wistrel;

end; { case }

if i<1 then i:= 10;

if i>10 then i:= 1;

if j<1 then j:= 10;

if j>10 then j:= 1;

if ibmkor=0 then xod:= 0;

until xod = 0;

end;

procedure ibmxod;

begin

repeat

i:= round(random(10))+1;

j:= round(random(10))+1;

until mypole[i,j]<>2;

putpixel(15+i*10,15+j*10,1);

if mypole[i,j]=1 then

begin

for i1:=i-1 to i+1 do

for j1:=j-1 to j+1 do

begin

mypole[i1,j1]:=2;

if (i1>0) and (i1<11) and (j1>0) and (j1<11) then

putpixel(15+i1*10,15+j1*10,1);

end;

line(10+i*10,10+j*10,20+i*10,20+j*10);

line(20+i*10,10+j*10,10+i*10,20+j*10);

dec(mykor);

end else begin mypole[i,j]:=2; xod:=1 end;

end;

{ }

begin

gd:=CGA; gm:=0; {- 640 x 480}

mmm:

for i:= 0 to 11 do

for j:= 0 to 11 do

begin

mypole[i,j]:= 0; { }

ibmpole[i,j]:= 0; { }

end;

initgraph(gd,gm,'egavga.bgi');

{ }

setcolor(1);

mykor:= 10; k:= 10; { }

for i:= 0 to 10 do line(20+10*i,20,20+10*i,120); { }

for i:= 0 to 10 do line(20,20+10*i,120,20+10*i);

{ - }

ibmkor:= 10; kk:= 10; { }

for i:= 0 to 10 do line(200+10*i,20,200+10*i,120); { }

for i:= 0 to 10 do line(200,20+10*i,300,20+10*i);

ibmkorabel;

i:= 1; j:= 1;

repeat

Setcolor(2);Rectangle(10+10*i,10+10*j,20+10*i,20+10*j);

ch:= readkey;

Setcolor(1);Rectangle(10+10*i,10+10*j,20+10*i,20+10*j);

case ch of

{ left } #75: dec(i);

{ right} #77: inc(i);

{ up } #72: dec(j);

{ down } #80: inc(j);

#32: korabel;

end; { case }

if i<1 then i:= 10;

if i>10 then i:= 1;

if j<1 then j:= 10;

if j>10 then j:= 1;

until k = 0;

{ }

xod:=1;

repeat

if (ibmkor<>0) and (mykor<>0) then if xod=1 then myxod else ibmxod;

until (ibmkor=0) or (mykor=0);

if ibmkor = 0 then outtextxy(30,150,' ! ')

else if mykor=0 then outtextxy(30,150,' ! ');

outtextxy(30,180,' ? (Y/N)');

ch:= readkey;

st:=ch;

if (st = 'Y') or (st = 'y') then goto mmm;

closegraph;

end.

11.3, , . , .

222. 222. (ղ . , 1999 .)

. i CHESS.DAT (, 5) i (, 7) i . CHESS.SOL ii ii i N i i . i N i i i i ii i i . i' CHESS.*

i: i i i i: A,B,C,D,E,F,G,H, i 18.

i i :

CHESS.DAT CHESS.SOL

A5 C7 4

B3

D4

B5

C7

: , .

. 1

. , 6. , . ( , ) ( ). (Xstart, YStart) (Xfine, YFine), ( ). ³ . : , , .

. , , 1, .

, :

. 2.
                   
                   
                   
                   
                   
                   
                   
                   
                   
          . 3      
                                   

n , , , , , 1 , , ;

n : k = X10+Y;

n , , .

, , . 2, 3. .

, , , , 1 , . : x = k div 10, y = k mod 10, k , . , , . .

. ( hod). .

program chess;

const inname = 'chess.dat';

outname = 'chess.sol';

var area, point: array[1..8,1..8] of byte;

namex: array[1..8] of char;

i, j, XStart, YStart, XFine, YFine, X, Y, step: byte;

f: text;

kod: integer;

c: char; st, st1: string;

flag: boolean;

procedure hod(x, y, step: byte);

begin

if (x - 2 > 0) and (y - 1 > 0) and (area[x-2,y-1] = 0) then

begin

area[x-2,y-1]:= step + 1;

point[x-2,y-1]:= 10*x + y;

end;

if (x-2 > 0) and (y+1 < 9) and (area[x-2,y+1] = 0) then

begin

area[x-2,y+1]:= step + 1;

point[x-2,y+1]:= 10*x + y;

end;

if (x+2 < 9) and (y-1 > 0) and (area[x+2,y-1] = 0) then

begin

area[x+2,y-1]:= step + 1;

point[x+2,y-1]:= 10*x + y;

end;

if (x+2 < 9) and (y+1 < 9) and (area[x+2,y+1] = 0) then

begin

area[x+2,y+1]:= step + 1;

point[x+2,y+1]:= 10*x + y;

end;

if (x-1 > 0) and (y-2 > 0) and (area[x-1,y-2] = 0) then

begin

area[x-1,y-2]:= step + 1;

point[x-1,y-2]:= 10*x + y;

end;

if (x-1 > 0) and (y+2 < 9) and (area[x-1,y+2] = 0) then

begin

area[x-1,y+2]:= step + 1;

point[x-1,y+2]:= 10*x + y;

end;

if (x+1 < 9) and (y-2 > 0) and (area[x+1,y-2] = 0) then

begin

area[x+1,y-2]:= step + 1;

point[x+1,y-2]:= 10*x + y;

end;

if (x+1 < 9) and (y+2 < 9) and (area[x+1,y+2] = 0) then

begin

area[x+1,y+2]:= step + 1;

point[x+1,y+2]:= 10*x + y;

end;

end;

procedure back_and_print;

begin

assign(f, outname); rewrite(f);

st:= '';

X:= XFine; Y:= YFine;

repeat

st1:= namex[X]; st:= st + st1;

str(Y,st1); St:= st + st1;

XFine:= point[x,y] div 10;

YFine:= point[x,y] mod 10;

x:= xfine; Y:= Yfine;

until point[x, y] = 1;

writeln(f, step); writeln(step);

kod:= length(st) - 1;

while kod >= 1 do

begin

writeln(f,copy(st,kod,2));

writeln(copy(st,kod,2));

dec(kod,2);

end;

close(f);

end;

begin

fillchar(area, sizeof(area), 0);

fillchar(point, sizeof(point), 0);

namex[1]:='A';

for i:=2 to 8 do namex[i]:= succ(namex[i-1]);

assign(f, inname); reset(f); readln(f,st); close(f);

c:= st[1];

for i:=1 to 8 do if c=namex[i] then XStart:= i;

c:= st[2]; val(c,YStart,kod);

c:= st[4];

for i:=1 to 8 do if c=namex[i] then XFine:= i;

c:= st[5]; val(c, YFine, kod);

X:= XStart; Y: = YStart;

flag:= false; step:= 1;

area[xStart, yStart]:= step;

point[Xstart, yStart]:= 1;

while flag = false do

begin

for i:= 1 to 8 do

for j:= 1 to 8 do

if area[i,j] = step then hod(i, j, step);

if area[XFine,YFine] > 0

then flag:= true

else inc(step);

end;

back_and_print;

end.

 

 

223. 223. , n 90, 180 270 , .

224. 224. n 12 . , :

) ;

) .

225. 225. , . .

226. 226. m n:

) k i p;

) k i p.

227. 227. n , :

228. 228. , . M N. , 2,..., n.

229. 229. , , . .

230. 230. MxN 0 1 , . . , .

231. 231. 䒺 . 䳿: 1 . .

232. 232. , , + 1, + 2,..., n, 1, 2,..., 1.

1 = 1

2 = 2

...

xn = cn

, , . , .

233. 233. , , .

234. 234. M N, :

) ;

) .

235. 235. 8 , . .

236. 236. , .

237. 237. N. , , . . . (1,1) (,), , , , , .

238. 238. , .

239. 239. , .

240. 240. N , , 0. , .

241. 241. , . , .

242. 242. N . , , , .

 

 

, ,

 

, . , . , , .

? , , , , , . , . 쳺 , . 1- : , , , ᒺ. , : ᒺ, , , .

. :

type < > = set of < >;

, , 256. , . , , .

, :

n in . , , :

cifra: set of char;

:

cifra:= [0..9];

ch char :

...

ch:= readkey;

if ch in cifra then write( );

...

n + ᒺ . , ={1,2,3,4,5}, a B={4,5,6,7}, =+ ={1,2,3,4,5,6,7}.

n . , ={1,2,3,4,5}, a B={4,5,6,7}, = ={1,2,3}.

n * . , ={1,2,3,4,5}, a B={4,5,6,7}, =* ={4,5}.

, , . .





:


: 2016-11-18; !; : 369 |


:

:

, , .
==> ...

1335 - | 1256 -


© 2015-2024 lektsii.org - -

: 0.109 .