Amalik0
01.08.2021 01:07

#include

#include

#include

#include

#define NN 1000000

#define eps 1e-7

int n;

double C;

double a[NN], p[NN];

int h[NN];

int s, t, i, j;

double l, r;

double

get_h (void)

{

assert (s < t);

return a[h[s]];

}

int

pop_h (void)

{

assert (s < t);

return h[s++];

}

void

push_h (int x)

{

while (s < t && a[h[t - 1]] < a[x])

t--;

h[t++] = x;

}

int

main (int argc, char *argv[])

{

double ev, ev1, ev2;

int x;

scanf ("%d%lf", &n, &C);

for (i = 0; i < n - 1; i++)

scanf ("%lf", &a[i]);

for (i = 0; i < n; i++)

p[i] = 0;

s = 0; t = 0;

i = 0; j = 1;

l = C; r = 0;

push_h (0);

// printf('\n');

while (j < n && i < j && l > a[j - 1] + eps)

{

ev1 = (l - r) * (j - i) / (j - i + 1);

if (s < t)

{

ev2 = (l - get_h ()) * (j - i);

ev = (ev1 < ev2) ? ev1 : ev2;

}

else

ev = ev1;

l -= ev / (j - i);

r += ev;

assert (l + eps > r);

if (fabs (l - r) < eps)

{

push_h (j);

j++;

r = 0;

}

if (fabs (l - get_h ()) < eps)

{

x = pop_h ();

for (; i <= x; i++){

p[i] = l;

}

i = x + 1;

}

if ((i == j) || (l < a[j - 1] + eps))

{

for (; i < j; i++){

p[i] = l;

}

l = r;

r = 0;

i = j;

push_h (j);

j++;

}

}

for (; i < j; i++){

p[i] = l;

}

for (i = 0; i < n; i++)

printf ("%0.20lf\n", p[i]);

return 0;

}

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
kodir74
10.09.2021 04:54
Program str;
 Uses crt;
Var   s:string;  
i,p,sum:integer;
Begin     
         P:=1;     
         Sum:=0;     
         Readln(s);     
         For i:=1 to length(s) do     
               Begin      
          If s[i] in ['0'..'9'] then                       
                                       Begin                           
                                               p:=p*(ord(s[i])-ord('0'));                                                                                         sum:=sum+(ord(s[i])-ord('0'));                     
                                       End;     
               End;     
Writeln('Сумма = ',sum,' ','Произведение = ',p);
End.
0,0(0 оценок)
Ответ:
женя1084
06.03.2021 00:18
Var s1,s2:string;
begin;
writeln('Введите исходные знаки');
readln(s1);
readln(s2);
if ((s1<>'-') and (s1<>'+')) or ((s2<>'-') and (s2<>'+')) then
begin;
writeln('Ошибка');
exit;
end;
if ((s1='+') and (s2='+')) or ((s1='-') and (s2='-')) then writeln('+') else writeln('-');
end.

С числами:
var a,b:integer;
begin;
writeln('Делимое:');
readln(a);
writeln('Делитель');
readln(b);
if b=0 then
begin;
writeln('Нельзя делить на ноль. Если это, конечно, не JavaScript.');
exit;
end;
if a=0 then
begin;
writeln('0');
exit;
end;
if ((a>0) and (b>0)) or ((a<0) and (b<0)) then writeln('+') else writeln('-');
end.
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота