procedure cube(a,b,c,d,e:real); Var p,q,delta,phi,i:real; y:array[1..3] of real; begin p:=(3*a*c-sqr(b))/(3*sqr(a)); q:=(2*power(b,3)-9*a*b*c+27*sqr(a)*d)/(27*power(a,3)); delta:=power(q/2,2)+power(p/3,3); if delta<0 then begin if q<0 then phi:=arctan(sqrt(-delta)/(-q/2)); if q>0 then phi:=arctan(sqrt(-delta)/(-q/2))+pi; if q=0 then phi:=pi/2; y[1]:=2*sqrt(-p/3)*cos(phi/3); y[2]:=2*sqrt(-p/3)*cos(phi/3+(2*pi)/3); y[3]:=2*sqrt(-p/3)*cos(phi/3+(4*pi)/3); var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a),y[3]-b/(3*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; if delta>0 then begin var arsom:=range(0,1000).Where(x->(a*power(x,3)+b*x*x+c*x+d)/(x-e)=0); write(arsom.Count); {Мы не виноваты, Паскаль не может в комплексные числа} end; if delta=0 then begin y[1]:=2*power(-q/2,1/3); y[2]:=-power(-q/2,1/3); var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; end;
procedure square(a,b,c,e:real); Var d:real; begin d:=sqr(b)-4*a*c; if d<0 then writeln('0'); if d>0 then begin var x:=arr((-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; if d=0 then begin var x:=arr(-b/(2*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; end;
procedure common(a,b,e:real); begin var x:=arr(-b/a); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end;
procedure awfulvar(e:real); begin if (e>=0) and (e<=1000) then writeln('1000') else writeln('1001'); end;
procedure otherawfulvar(e:real); begin if e<>0 then writeln('1') else writeln('0'); end;
begin read(a,b,c,d,e); if (a<>0) and (b<>0) then cube(a,b,c,d,e); if (a=0) and (b<>0) then square(b,c,d,e); if (a=0) and (b=0) and (c<>0) and (d<>0) then common(c,d,e); if (a=0) and (b=0) and (c=0) and (d=0) then awfulvar(e); if (a=0) and (b=0) and (c<>0) and (d=0) then otherawfulvar(e); if (a=0) and (b=0) and (c=0) and (d<>0) then writeln('0'); end.
Const n=8; var a:array[1..n,1..n] of integer; i,j,k,s,s1,si,dmin,smin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(50); write(a[i,j]:4); end; writeln; end; write('k = '); readln(k); s:=0; for j:=1 to n do s:=s+a[k,j]; writeln('s = ',s); dmin:=999999; smin:=999999; for i:=1 to n do if i<>k then begin s1:=0; for j:=1 to n do s1:=s1+a[i,j]; writeln('s',i,' = ',s1); if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end; end; writeln('Номер строки = ',si,', smin = ',smin); end.
//Pascal ABC.NET 3.1 сборка 1256
Var
a,b,c,d,e:real;
procedure cube(a,b,c,d,e:real);
Var
p,q,delta,phi,i:real;
y:array[1..3] of real;
begin
p:=(3*a*c-sqr(b))/(3*sqr(a));
q:=(2*power(b,3)-9*a*b*c+27*sqr(a)*d)/(27*power(a,3));
delta:=power(q/2,2)+power(p/3,3);
if delta<0 then
begin
if q<0 then
phi:=arctan(sqrt(-delta)/(-q/2));
if q>0 then
phi:=arctan(sqrt(-delta)/(-q/2))+pi;
if q=0 then
phi:=pi/2;
y[1]:=2*sqrt(-p/3)*cos(phi/3);
y[2]:=2*sqrt(-p/3)*cos(phi/3+(2*pi)/3);
y[3]:=2*sqrt(-p/3)*cos(phi/3+(4*pi)/3);
var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a),y[3]-b/(3*a));
write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count);
end;
if delta>0 then
begin
var arsom:=range(0,1000).Where(x->(a*power(x,3)+b*x*x+c*x+d)/(x-e)=0);
write(arsom.Count);
{Мы не виноваты, Паскаль не может в комплексные числа}
end;
if delta=0 then
begin
y[1]:=2*power(-q/2,1/3);
y[2]:=-power(-q/2,1/3);
var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a));
write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count);
end;
end;
procedure square(a,b,c,e:real);
Var
d:real;
begin
d:=sqr(b)-4*a*c;
if d<0 then writeln('0');
if d>0 then
begin
var x:=arr((-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a));
write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count);
end;
if d=0 then
begin
var x:=arr(-b/(2*a));
write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count);
end;
end;
procedure common(a,b,e:real);
begin
var x:=arr(-b/a);
write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count);
end;
procedure awfulvar(e:real);
begin
if (e>=0) and (e<=1000) then writeln('1000') else writeln('1001');
end;
procedure otherawfulvar(e:real);
begin
if e<>0 then writeln('1') else writeln('0');
end;
begin
read(a,b,c,d,e);
if (a<>0) and (b<>0) then cube(a,b,c,d,e);
if (a=0) and (b<>0) then square(b,c,d,e);
if (a=0) and (b=0) and (c<>0) and (d<>0) then common(c,d,e);
if (a=0) and (b=0) and (c=0) and (d=0) then awfulvar(e);
if (a=0) and (b=0) and (c<>0) and (d=0) then otherawfulvar(e);
if (a=0) and (b=0) and (c=0) and (d<>0) then writeln('0');
end.
Пример ввода:
1
1
1
1
1
Пример вывода:
0
var
a:array[1..n,1..n] of integer;
i,j,k,s,s1,si,dmin,smin:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(50);
write(a[i,j]:4);
end;
writeln;
end;
write('k = '); readln(k);
s:=0;
for j:=1 to n do s:=s+a[k,j];
writeln('s = ',s);
dmin:=999999; smin:=999999;
for i:=1 to n do
if i<>k then
begin
s1:=0;
for j:=1 to n do s1:=s1+a[i,j];
writeln('s',i,' = ',s1);
if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end;
end;
writeln('Номер строки = ',si,', smin = ',smin);
end.
Пример:
Исходный массив:
9 0 22 40 20 35 2 25
23 30 22 35 41 0 9 40
1 15 6 18 43 47 34 33
26 5 2 45 13 46 40 2
26 39 7 31 3 43 20 8
25 15 24 6 10 16 3 25
47 0 27 35 14 15 36 11
16 38 14 14 33 7 11 26
k = 5
s = 177
s1 = 153
s2 = 200
s3 = 197
s4 = 179
s6 = 124
s7 = 185
s8 = 159
Номер строки = 4, smin = 179