a) b)
2 - , .
b1=false b2=0.
- : , .
. , , , cand (conditional and, ). and . .
) , .
( ). , , true false.
- , .
A(x) B(x) , , , . A(x) T1 B(x) T2, T = T1 ∩ T2. : A(x): x , B(x): x 3. A(x) B(x) x x 3. x 6.
A(x) B(x) , x T, . A(x) B(x).
A(x) , x T, A(x) , A(x) .
x X T' T X.
A(x) B(x) , x T, A(x) , B(x) , . : A(x), B(x).
) .
(-) , . . - , . , . . , , . .
|
|
) (-) , . (). , .
) 1. .
()
(). All- . , , , . () ( ), .
1: ()
- .
, () . .
2. .
P(x) - . , , , P(x) , . x. : x, P(x) . . x ( )
10
A:array[I] of T, ( , ). I .
i | ||||||||
x |
X[i]:= ( X[i]); ( X[i]) ;
X[i]:= - ;
( , , ) ( ), . , () . , , .
:
:
1. : I [1..n], [0..n]. n. - ; f: NT, .. [1,n] T
2. . f: IT. I , I T . .
, ( ) - ( ). A[e] A , e I (a[e]=app(a,e) ). , .
|
|
( )
.
array[I1] of array [I2] of T
.
array[I1,,In] of T; a[c1,,cn];
n.
: .
: [a, , s], N ( ).
{ki i- }
assign(f,);
reset(f);
for c:=a to z do k[c]:=0;
while not eof(f) do
begin
read(f,c);
k[c]:=k[c]+1;
end;
close(f);
( - )
Found:=
ai=x
$ iÎ[1,len(a)] (ai>=x)
: i, x<=ai, found:=true Û x=ai, ; , found:=false.
, i: ai>=x
found1:=$i (ai>=x)
assign(f,);
reset(f);
found1:=false;
while (not found1) and (not eof(f)) do
begin
read(f,a);
if a>=x then found1:=true
end;
if found1 then found:=a=x
else found:=false;
( - )
Program Binar;
Var a:array[1..n] of integer;
l,r,m:integer;
found:boolean;
Begin
{ a}
l:=1;
r:=n;
found:=false;
while (l<=r) and not found do
begin
m:=(l+r) div 2;
if a[m]=x
then found:=true
else if a[m]<x then l:=m+1
else r:=m-1;
end;
end.
11
.
(){
.}
() {
}
, .
i Î [1,length(a)] (ai<=ai+1)
i,j Î [1,length(a)] (i<=j → ai<=aj)
, .
.
() {
- , () : .. }
Program Binar;
Var a:array[1..n] of integer;
l,r,m:integer;
found:boolean;
Begin
{ a}
l:=1;
r:=n;
found:=false;
while (l<=r) and not found do
begin
m:=(l+r) div 2;
if a[m]=x
then found:=true
else if a[m]<x then l:=m+1
else r:=m-1;
end;
end.
{ , , , .. }
().
(){
- , ,(?), . }
() {
, , , , , }
12