Aztec Pyramid
题意:给n个木块堆放,最高能堆多少层,要求除了地面的木块其他木块满足该木块下一层的正下方已经其正下方的上下左右都有木块。
解法:直接按照最优的方案堆积
#include <iostream>
#include <stdio.h>
using namespace std;
int a[10000010],sum[10000010];
int main() {
freopen("aztec.in","r",stdin);
freopen("aztec.out","w",stdout);
a[0]=1;
sum[0]=1;
for (int i = 1;; i++) {
a[i] = a[i-1]+i*4;
sum[i] = sum[i-1]+a[i];
if (sum[i] > 1000000000) break;
}
int n;
while (scanf("%d",&n) != EOF) {
int i = 0;
while (1) {
if (sum[i] > n)
break;
else i++;
}
cout << i << endl;
}
fclose(stdin);fclose(stdout);
}