-













































:

:

: 7 , 1 , 1 , 35 .

: , , , , , , , , , , , .

: .

: , .

, : , .

充..5 .

1.   ..6 .

2.   11 .

3.   腅.14 .

3.1 充14 .

3.2 .14 .

4.   Turbo Pascal..15 .

4.1 ...15 .

4.2 1...26 .

4.3 2...26 .

4.4 .27 .

5.   28 .

充33 .

..34 .

.35 .

.

, .

. , , , , , . ([1])

, , .

, . , .

.

, , .

1.   .

, , , . , . .

, . G = (V,E), V , , Í V X V Í{{,}: , Î V ۸ ¹} . |V| = n || = m.

. n , , m , . , <x, y> Î E, 1 , , 1 , , (, . . <x, x>, , , 2). , {,}, 1 , , . . 2.1. , , , . -, nm , . . <x,y>?, ? , , m .

, = [bj] nm,

<1,2>

<1,3>

<3,2>

<3,4>

<5,4>

<5,6>

<6,5>

() 1 1 1 0 0 0 0 0

2 1 0 1 0 0 0 0

3 0 1 -1 -1 0 0 0

4 0 0 0 1 1 0 0

5 0 0 0 0 -1 -1 1

6 0 0 0 0 0 1 -1

 


{1,2}

{1,3}

{1,5}

{2,3}

{2,5}

{3,4}

{4,5}

{4,6}

{5,6}

() 1 1 1 1 0 0 0 0 0 0

2 1 0 0 1 1 0 0 0 0

3 0 1 0 1 0 1 0 0 0

4 0 0 0 0 0 1 1 1 0

5 0 0 1 0 1 0 1 0 1

6 0 0 0 0 0 0 0 1 1

. 1. ) ;

) .

bij = 1, , , bij = 0 . , {, } , , . . 2.

, y?. , n2. , () n.

,

, .

P(G) = 0 P(G)=1 , G . , :

() P(G)=P(G'), G G' ;

() P(G) = 0 <V,Æ> P(G)=1 <V, P2(V)> ;

1 2 3 4 5 6 1 2 3 4 5 6

1 0 1 1 0 0 0 1 0 1 1 0 1 0

2 0 0 0 0 0 0 2 1 0 1 0 1 0

3 0 1 0 1 0 0 3 1 1 0 1 0 0

4 0 0 0 0 0 0 4 0 0 1 0 1 1

5 0 0 0 1 0 1 5 1 1 0 1 0 1

6 0 0 0 0 1 0 6 0 0 0 1 1 0

. 2. .1.

() , . . P(G)<P(G') G=(F,E) G'=(V, E'),  = '.

( , , ).

. , (), (), (), , (. . P(G) G) , Ω(n2) , n .

, , , .

() P(G) = P(G') G = < V, E>, G = < V, > U <v, v>>, v C V.

蠠 ( , , m n2) , . <x, > <, >, , {, y} (. 3). , 2. , , .

, ,

1 2
1 3
1 5
2 3
2 5
3 4
4 5
4 6
5 6
1 2
1 3
3 2
3 4
5 4
5 6
6 5



.3. .1.

, . v C V , v -> u ( v ). , , . . (. = nil ). ; , HA[v] , {u: v+u} ({u: v - u} ). 3A[v], , , , , for u C [v] do ....

, {u, v} : v [u] [v]. . , [u], , 3AC[v], , , .

()

 


.4. [v], v =V, .1.

, , , , , , .

[v], (u: u -> v).

, , , , m + n. .4 , . 1.

2. .

, (: breadth first search). , , , , , . , , . , , . , ( ), ( ). . ( , , , , ).

1 procedure WS (v);

(* v;

, *)

2 begin

3 := Æ; <= v; [v] :=

4 while ¹ Æ do

5 begin <= ; ;

6 for u Î [] do

7 if [u] then

8 begin <= u; [u]:=

9 end

10 end

11          end

: 7- [u] () v- u- . v- - . , , , v- - , .. . , .

1 procedure Write_S;

2 begin

3 for v Î V do [u]:= ; (* *)

4 for v Î V do

5 if HOB[v] then WG(v)

6 end

, , , , WS(v) , v, . (m + n), , 6, , .

, 0 v (. . v), , v, . . , 1 v, . . . , , , r, v, , v r, . , , , u , , + 1 v. , r v, (), , , r + 1 v, , r + 1.

. 5 , , .

, WS ,

10(7)

 


. 5 ( ), , .

[v], v = V, . , , ,

3.

3.1

ver , 0 1000;

nv - ;

ocher , ;

raz , ;

schet ;

key ;

mgsi , ;

prosm - , WS ;

find - , ;

craz, menu, mg, sormen .

3.2

Make_Graph ;

WS - v- ;

Write_S WS;

Sort - .

4. TURBO PASCAL

4.1 .

{$S+} {$R+} {$I+} {$M 65520,0,655360}

program graph;

uses crt,newtimer;

const

maxraz=400;

type index=^list;

list= record

inf: word;

next: index;

end;

connection=array[1..maxraz] of index;

var

el,em,size: pointer;

lst,m: connection;

ver: array[1..maxraz] of word; { }

Nw: array[1..maxraz] of boolean;

ocher: array[1..maxraz+1] of integer;

raz: integer;

exch,fil,i,j,l,schet,v,u,p: word;

key,kols,t,tm: longint;

mgsi,mem,sor,prosm,find: boolean;

craz,menu,mg,sormen:char;

{------------------------------------------------------

*** ***}

procedure Make_Graph(mgsi: boolean);

label Er;

var

n: index;

i,j: word;

kolvo: longint;

spro: boolean;

begin

randomize;

for i:=1 to raz do begin

ver[i]:=random(1000);

end;

kolvo:=0;

for i:=1 to raz do begin

lst[i]:=nil;

for j:=1 to raz do begin

spro:=true;

if j=raz then goto Er;

if j=i then inc(j);

n:=nil;

n:=lst[j];

if lst[j]<>nil then

repeat

if n^.inf=ver[i] then spro:=false;

n:=n^.next;

until (n=nil) or (not(spro));

if (round(random)=1) and spro then

begin

new(m[i]);

inc(kolvo);

m[i]^.inf:=ver[j];

m[i]^.next:=lst[i];

lst[i]:=m[i];

end;

Er:

end;

end;

writeln;

if mgsi then { }

for i:=1 to raz do {}

begin {}

write(ver[i],'-'); {}

m[i]:=lst[i]; {}

if m[i]<>nil then {}

repeat {}

write(m[i]^.inf,'═'); {}

m[i]:=m[i]^.next; {}

until m[i]=nil; {}

writeln(''); writeln; {}

end; {}

writeln('- : ',kolvo);

end;

{------------------------------------------------------

*** v- ***}

Procedure WS(v:word; var find: boolean;

var schet: word);

var {v - . }

ik,oo,o9,o3,op: integer;

rebro: boolean;

begin { - }

ocher[1]:=v; oo:=1; { }

Nw[v]:=False; { }

while oo>0 do begin { ...}

p:=ocher[1];{ 1- p}

for op:=1 to oo-1 do ocher[op]:=ocher[op+1]; ocher[oo]:=0;

dec(oo);

inc(schet); { }

if not(prosm) and (ver[p]=key) then {if ver[p]=key...}

begin

find:=true;

exit; { }

end;

{ () }

if prosm then begin

if wherex>=79 then writeln;

write(ver[p],' ');

end;

o9:=oo;

for u:=1 to o9 do {u }

begin

rebro:=false;{ ver[v] ver[u] }

{ v- }

m[v]:=lst[v];

while m[v]<>nil do

begin { ver[u] v- }

if m[v]^.inf=ver[u] then begin

{ } rebro:=true;

break;

end;

m[v]:=m[v]^.next; { ...}

end;

{ , ver[v] u- , .. ...}

if not(rebro) then

begin

m[u]:=lst[u];{ u- }

while m[u]<>nil do

begin

if m[u]^.inf=ver[v] then begin

rebro:=true;

break;

end;

m[u]:=m[u]^.next;

end;

end;

{ u- ...}

if rebro and Nw[u] then

begin

inc(oo); { u }

for op:=oo downto 2 do ocher[op]:=ocher[op-1];

ocher[1]:=u;

Nw[u]:=False;{ u}

end;

end;

end;

end;

{------------------------------------------------------

*** ***}

Procedure Write_S(key: longint; prosm: boolean;

var find: boolean; var schet: word);

begin

{ }

for i:=1 to raz do Nw[i]:=true;

for i:=1 to raz do

{ raz i- , i- }

if Nw[i] and not(find) then WS(i,find,schet);

end;

{------------------------------------------------------

*** ***}

procedure Sort;

begin

for l:=1 to raz-1 do

for j:=1 to raz-l do

if ver[j]>ver[j+1] then

begin

exch:=ver[j];

el:=lst[j];

em:=m[j];

ver[j]:=ver[j+1];

lst[j]:=lst[j+1];

m[j]:=m[j+1];

ver[j+1]:=exch;

lst[j+1]:=el;

m[j+1]:=em;

end;

end;

{=====================================================}

begin

while menu<>'4' do

begin

textmode(1);

textbackground(blue);

clrscr;

textcolor(red);

gotoxy(16,3); writeln(' ');

textcolor(white);gotoxy(5,5);

writeln('* *');

textcolor(black); gotoxy(7,22);

writeln('Created by Andrew Spikhailo');

gotoxy(15,24); write('ARMAVIR 2001');

textcolor(white);

gotoxy(7,10); write('┌───────────MENU───────────╖');

gotoxy(7,11); write('│');textcolor(green);

write('1 ࠠ '); textcolor(white);write('║');

gotoxy(7,12); write('│');textcolor(green);

write('2 ࠠ '); textcolor(white);write('║');

gotoxy(7,13); write('│');textcolor(green);

write('3 ࠠ '); textcolor(white);write('║');

gotoxy(7,14); write('│');textcolor(green);

write('4 䠠 '); textcolor(white);write('║');

gotoxy(7,15); write('│');textcolor(white+128);

write(' '); textcolor(white);write('║');

gotoxy(7,16); write('╘══════════════════════════╝');

menu:=readkey;

case menu of

'1': begin

{ , }

textmode(2);

textbackground(blue);

clrscr; textcolor(lightgreen);

if mem then release(size);

repeat

clrscr;

write(' : ');

writeln('(1) - ');

gotoxy(21,wherey);

writeln('(2) - ');

gotoxy(21,wherey);

writeln('(3) - ');

gotoxy(21,wherey);

write('(4) - ...');

raz:=0;

repeat

craz:=readkey;

case craz of

'1': raz:=10;

'2': raz:=100;

'3': raz:=400;

'4': begin

write(' ___');

gotoxy(wherex-3,wherey);

read(raz);

if (raz<=0) or (raz>400) then begin

raz:=0;

gotoxy(38,wherey-1);

write('ERROR...');

delay(1000);

end;

end;

end;

until (craz='1') or (craz='2') or (craz='3') or (craz='4');

clrscr;

until raz>0;

writeln;

write(' : ');

writeln('0 - ');

gotoxy(35,wherey);

write('1 - ');

mg:=readkey;

if mg='1' then mgsi:=true

else mgsi:=false;

clrscr;

mark(size);

Make_Graph(mgsi);

mem:=true;{ }

sor:=false; { }

readkey;

end;

'2': begin { }

textmode(2);

textbackground(blue);

clrscr; textcolor(lightgreen);

gotoxy(32,3); Writeln(' :');

key:=-1;

find:=false;

prosm:=true; schet:=0;

Write_S(key,prosm,find,schet); writeln;

readkey;

end;

'3': begin { }

clrscr; textcolor(lightgreen);

if not(sor) then begin

writeln(' ?');

writeln(' 1-');

writeln(' 2-');

sormen:=readkey;

if sormen='1' then begin

Sort;

sor:=true;

end;

end;

prosm:=false;

write(' : ');

readln(key); writeln;

start(t);

kols:=0;

for fil:=1 to 10000 do

begin

schet:=0;

find:=false;

Write_S(key,prosm,find,schet); { }

kols:=kols+schet;

end;

stop(t);

if not(find) then write(' ...')

else begin

writeln(' ',ver[p],' !');

writeln(' : ',kols/10000:5:1);

report(' ',t);

end;

readkey;

end;

end;

end;

end.

4.2 1.

5, .

:

74 497-174-

174

55 497-

497

661 497-

- : 4

: 74 174 55 497 661

: (nil).

.6

55 74

497

661 174

. 6

4.3 2.

7, .

:

704 66-373-434-

434 373-

766 706-373-434-

373 66-

66

706 66-704-

454 706-66-373-

- : 13

: 704 434 766 373 66 706 454

: (nil).

.7

704

454 66

373 434

706 766

. 7

4.4 .

, :

1

2

3

4 .

1, 2, 3 4.

)

, : 10, 100, 400 .

, . , 1 , 0 .

) ໠

, .

) ໠

. , . Start,Stop Report, Newtimer. Newtimer .

)

.

5.

, 100, 200 400 , .

10, , :

97 920 635 286 590 938 981 716 427 474

: 427

427 !

: 9.0

: 23:53:46.50

: 23:53:46.66

: 0.00001 cek.

10, , :

32 192 234 243 297 324 775 804 982 986

: 192

192 !

: 2.0

: 23:55:28.33

: 23:55:28.44

: 0.00001 cek.

100, , :

575 128 905 777 923 75 716 446 477 627 70 591 250 555 111 208 315 417 309 723 963 250 561 966 790 982 965 446 228 1 344 446 237 552 912 756 142 875 665 83 863 265 369 427 0 476 253 987 537 135 768 374 117 86 12 204 149 849 694 332 219 600 738 310 532 358 882 844 394 285 899 302 940 293 276 569 607 350 478 806 95 190 153 891 774 322 876 605 798 525 310 851 399 246 876 464 91 567 308 386

: 293

293 !

: 74.0

: 23:58:09.98

: 23:58:11.08

: 0.00010 cek.

100, , :

0 1 12 70 75 83 86 91 95 111 117 128 135 142 149 153 190 204 208 219 228 237 246 250 250 253 265 276 285 293 302 308 309 310 310 315 322 332 344 350 358 369 374 386 394 399 417 427 446 446 446 464 476 477 478 525 532 537 552 555 561 567 569 575 591 600 605 607 627 665 694 716 723 738 756 768 774 777 790 798 806 844 849 851 863 875 876 876 882 891 899 905 912 923 940 963 965 966 982 987

: 293

293 !

: 30.0

: 23:59:08.14

: 23:59:08.80

: 0.00006 cek.

400, , :

963 663 915 353 650 103 540 531 548 338 960 515 143 963 765 42 822 188 102 85 361 193 137 582 756 241 325 234 400 482 104 416 826 611 874 500 505 805 365 134 436 606 755 278 513 684 151 42 895 633 291 621 873 249 566 877 965 925 747 359 220 126 991 823 970 79 18 524 513 127 551 851 462 403 375 88 739 754 645 357 457 82 274 23 171 523 537 131 227 148 231 657 201 88 12 620 660 273 759 359 725 191 88 517 178 361 361 527 92 412 803 656 220 967 597 889 625 740 50 219 289 519 202 120 687 957 483 263 554 353 273 769 330 825 486 546 26 566 520 501 487 96 201 682 288 677 570 647 745 329 619 594 787 100 348 70 661 523 736 286 699 434 505 345 659 558 767 930 339 559 923 246 477 449 428 262 152 551 269 552 182 421 277 286 252 408 624 157 746 782 119 302 534 581 163 506 184 622 470 239 341 330 908 326 255 318 89 294 696 884 536 687 729 849 570 903 100 412 251 359 207 930 994 3 888 816 722 499 517 955 649 619 145 328 80 633 657 752 805 761 195 920 978 963 318 152 560 634 643 533 715 982 950 369 742 156 980 111 421 401 411 194 876 797 756 449 306 387 158 3 213 719 314 861 968 122 21 570 826 242 79 648 768 660 520 702 755 610 420 391 267 114 759 683 235 77 71 46 722 136 875 526 966 306 108 858 644 729 54 46 460 71 499 85 428 356 103 737 445 289 210 538 31 371 595 466 328 342 874 924 727 757 563 981 730 734 23 18 911 181 769 228 73 43 886 626 977 359 527 483 236 196 741 382 250 731 95 291 273 51 843 342 988 453 621 228 190 296 897 399 438 703 663 466 789 656 110 504 964 289 260 154 570 413 796 709

226 583 573 611 701 244 544 10 436 759 86 333 44 364

: 228

228 !

: 342.0

: 00:03:13.99

: 00:03:18.83

: 0.00048 cek.

400, , :

3 3 10 12 18 18 21 23 23 26 31 42 42 43 44 46 46 50 51 54 70 71 71 73 77 79 79

80 82 85 85 86 88 88 88 89 92 95 96 100 100 102 103 103 104 108 110 111 114 119 120 122 126 127 131 134 136 137 143 145 148 151 152 152 154 156 157 158 163 171 178 181 182 184 188 190 191 193 194 195 196 201 201 202 207 210 213 219 220 220 226 227 228 229 231 234 235 236 239 241 242 244 246 249 250 251 252 255 260 262 263 267 269 273 273 273 274 277 278 286 286 288 289 289 289 291 291 294 296 302 306 306 314 318 318 325 326 328 328 329 330 330 333 338 339 341 342 342 345 348 353 353 356 357 359 359 359 359 361 361 361 364 365 369 371 375 382 387 391 399 400 401 403 408 411 412 412 413 416 420 421 421 428 428 434 436 436 438 445 449 449 453 457 460 462 466 466 470 477 482 483 483 486 487 499 499 500 501 504 505 505 506 513 513 515 517 517 519 520 520 523 523 524 526 527 527 531 533 534 536 537 538 540 544 546 548 551 551 552 554 558 559 560 563 566 566 570 570 570 570 573 581 582 583 594 595 597 606 610 611 611 619 619 620 621 621 622 624 625 626 633 633 634 643 644 645 647 648 649 650 656 656 657 657 659 660 660 661 663 663 677 682 683 684 687 687 696 699 701 702 703 709 715 719 722 722 725 727 729 729 730 731 734 736 737 739 740 741 742 745 746 747 752 754 755 755 756 756 757 759 759 759 761 765 767 768 769 769 782 787 789 796 797 803 805 805 816 822 823 825 826 826 843 849 851 858 861 873 874 874 875 876 877 884 886 888 889 895 897 903 908 911 915 920 923 924 925 930 930 950 955 957 960 963 963 963 964 965 966 967 968 970 977 978 980 981 982 988 991 994

: 228

228 !

: 93.0

: 00:04:21.33

: 00:04:23.58

: 0.00022 cek.

, . , . , .

(400) , . 10000 . Newtimer :

T=Q/n ,

Q- ;

n (10000).

, , 1 , . , , , .

, .

, , , . . , . - , Visual C++, Visual BASIC , . ADA, OCCAM.([3]) , , , .

, : , - , , : , ; .. , ().

, , . , , , .

:

1.    . . .: , 1989.

2.    . . 7 . - .: , 1876.

3.    .. : . 220400 : , 1998.

4.         .., Turbo Pascal 7.0,

+, 1999 .

____________________________________________________

Newtimer

unit newtimer;

interface

procedure start(var x: longint); { }

procedure stop(var x: longint); { }

procedure format(hour, min, sec, hund: word);

procedure Report(Msg:string; x:longint);

implementation

uses dos;

var

hour_start, min_start, sec_start, hund_start,

hour_stop, min_stop, sec_stop, hund_stop,

hour, min, sec, hund: word;

systimer : longint absolute $0040 : $006c;

procedure start;

begin

gettime(hour_start, min_start, sec_start, hund_start);

x:=systimer;

while x=systimer do; { }

x:=systimer;

end;

procedure stop;

begin

gettime(hour_stop, min_stop, sec_stop, hund_stop);

x:=systimer-x;

end;

procedure format;

procedure print(w: word);

begin

if w<10 then write('0');

write(w);

end;

begin

print(hour); write(':');

print(min); write(':');

print(sec); write('.');

print(hund);

writeln;

end;

procedure Report;

{

Msg}

begin

write(' : ');

format(hour_start, min_start, sec_start, hund_start);

write(' : ');

format(hour_stop, min_stop, sec_stop, hund_stop);

writeln(msg,' : ',x/182000:5:5,' cek.');

end; end.


2012 , .