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.
//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, b, c: array [1..100] of longint;
i, min, n, j, t: longint;
begin
//Читаем количество элементов в нашем массиве.
readln(n);
//Читаем массив.
for i := 1 to n do read(a[i]);
//Заполняем первую "половинку".
for i := 1 to n div 2 do b[i] := a[i];
//Заполняем вторую "половинку". Но раз это уже вторая "половинка" главного массива, то и
//цикл теперь должен начинаться со второй части массива, а заканчиваться уже в его конце.
for i := n div 2 + 1 to n do c[i - n div 2] := a[i];
//Теперь отсортируем первую "половинку" методом выбора. Идея этого метода
//основывается на том, что мы ищем минимальный среди неотсортированных элемент,
//а затем аем его с тем, который стоит сразу после отсортированных.
for i := 1 to (n - 1) div 2 do
begin
min := i;
for j := i + 1 to n div 2 do
if b[min] > b[j] then
min := j;
if min <> i then begin
t := b[i];
b[i] := b[min];
b[min] := t;
end;
end;
//Затем вторую точно также, только стоит обратить внимание на сравнения.
//Так как надо отсортировать по убыванию, то теперь сравнение перед "swap"-ом
//будет другим.
for i := 1 to (n - 1) div 2 do
begin
min := i;
for j := i + 1 to n div 2 do
if c[min] < c[j] then
min := j;
if min <> i then begin
t := c[i];
c[i] := c[min];
c[min] := t;
end;
end;
//А теперь по очереди выводим готовые "половинки", не забывая ставить
//пробел после вывода каждого элемента.
for i := 1 to n div 2 do write(b[i], ' ');
for i := 1 to n - n div 2 do write(c[i], ' ');
end.