Pagini recente » Cod sursa (job #1450854) | Cod sursa (job #2283012) | Cod sursa (job #1737729) | Cod sursa (job #451771) | Cod sursa (job #757842)
Cod sursa(job #757842)
#include <cmath>
#include <fstream>
#include <algorithm>
using namespace std;
const double eps = 0.0000001;
int N;
double V[100002], powB[10002], S;
double A, B, R;
int done(double x)
{
double sum = S;
int resnow = 0;
for (int i = 1; i <= N; ++i)
{
double U = V[i];
if (U * (1 - A) >= x)
{
sum -= U * (1 - A);
U *= A;
++resnow;
int step = 1 << 13, times = -1;
for (; step; step >>= 1)
if (times + step <= 10000 && U * powB[times + step] * (1 - B) >= x)
times += step;
++times;
sum -= U - U * powB[times];
U *= powB[times];
resnow += times;
}
}
if (sum - R <= eps) return resnow;
return 0;
}
int main()
{
ifstream fin("minim2.in");
ofstream fout("minim2.out");
fin >> N;
for (int i = 1; i <= N; ++i)
{
fin >> V[i];
S += V[i];
}
fin >> A >> B >> R;
powB[0] = 1;
for (int i = 1; i <= 10000; ++i)
powB[i] = powB[i - 1] * B;
if (S - R <= eps)
{
fout << 0 << '\n';
fin.close();
fout.close();
return 0;
}
double l1 = 0, l2 = 1000000000;
while (l2 - l1 > eps)
{
double mid = (l1 + l2) / 2;
if (done(mid)) l1 = mid;
else l2 = mid;
}
fout << done(l1) << '\n';
fin.close();
fout.close();
}