题目
代码
#include <bits/stdc++.h>
using namespace std;
double qmi(double base, int expo)
{
double retval = 1;
while(expo)
{
if(expo & 1) retval /= base;
base *= base;
expo >>= 1;
}
return retval;
}
int main()
{
int n;
double rate;
scanf("%d%lf", &n, &rate);
double out = 0, in = 0;
for(int i = 0; i <= n; i++)
{
int x;
scanf("%d", &x);
if(x < 0) out += (-x) * qmi((rate+1), i);
else in += x * qmi((rate+1), i);
}
printf("%.3lf", in - out);
return 0;
}