C++ 代码
/*从后往前推导
发现E(n) = E(n-1) * 2 - H(n),
而最终E(n)至少为0*/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double E = 0;
int n,i;
cin >> n;
double H[n+1] = {0};
i = 1;
while(i <= n)
{
cin >> H[i];//存塔高
i++;
}
i = n;
while(i)
{ /*从编号N建筑一直到编号1建筑,0建筑不用算*/
E = ceil((E + H[i])/2.0);
// cout << E << H[i] <<endl;
i--;
}
int res = (int)E;
cout << res;
return 0;
}