Pagini recente » Cod sursa (job #1584439) | Cod sursa (job #2488614) | Cod sursa (job #394757) | Cod sursa (job #2090029) | Cod sursa (job #464848)
Cod sursa(job #464848)
#include<algorithm>
#include<stdio.h>
#include<math.h>
const int maxn = 100100;
long double eps = 1E-6;
using namespace std;
long double V[maxn];
long double ALFA,BETA,VAL;
int N;
long double ridic(long double val, int put)
{
long double val1 = val,rez = 1;
for(int i = 1;i <= put; i *= 2,val1 = val1 * val1)
if (i & put) rez = rez * val1;
return rez;
}
int ver(long double val)
{
long double s = 0;
for(int i = 1;i <= N; ++i)
{
long double aux = V[i];
if (aux * (1 - ALFA) >= val)
{
aux = aux * ALFA;
if (aux * (1 - BETA) >= val)
{
int nrm = (log(val) - log( aux ) - log (1.0 - BETA)) / log(BETA);
aux *= ridic(BETA,nrm);
while (aux * (1 - BETA) >= val)
{
aux *= BETA;
}
}
}
s += aux;
}
return s <= VAL;
}
int moves(long double val)
{
long double s = 0;
int rasp = 0;
for(int i = 1;i <= N; ++i)
{
long double aux = V[i];
if (aux * (1 - ALFA) >= val)
{
aux = aux * ALFA;
rasp++;
if (aux * (1 - BETA) >= val)
{
int nrm = (long double)log(val / aux / (1.0 - BETA)) / log(BETA);
aux *= ridic(BETA,nrm);
rasp += nrm;
while(aux * (1 - BETA) >= val)
{
aux *= BETA;
rasp++;
}
}
}
s += aux;
}
return rasp;
}
int main()
{
freopen("minim2.in","r",stdin);
freopen("minim2.out","w",stdout);
scanf("%d\n",&N);
long double dr = 0,st = 0;
for(int i = 1;i <= N; ++i)
{
scanf("%llf ", &V[i]);
dr = max(dr,(long double)V[i]);
}
scanf("%llf %llf %llf\n",&ALFA,&BETA,&VAL);
while(fabs(dr - st) >= eps)
{
long double mid = 0.5 * (st + dr);
if (ver(mid)) st = mid;
else dr = mid;
}
printf("%d\n",moves(st));
return 0;
}