问题链接:https://vjudge.net/problem/CodeForces-492A
问题简述:叠金字塔。第一层需要1个cube,第二层需要1+2=3个cube,第三层需要1+2+3=6个cube,第四层1+2+3+4=10个cube。现在有n个cube,问能叠多少层?
AC代码:
#include <iostream>
using namespace std;
int main()
{
long long a[200] = { 0,1 }, b[200] = { 0,1 };
int n;
cin >> n;
for (int i = 2; i < 200; i++)
{
a[i] = a[i - 1] + i;
b[i] = b[i - 1] + a[i];
if (b[i] > n)
{
cout << i-1 << endl;
break;
}
}
}