Aztec Pyramid |
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:262144KB |
Total submit users: 57, Accepted users: 49 |
Problem 12905 : No special judgement |
Problem description |
|
Input |
The only line of the input file contains a single integer number n — the number of available blocks, including the first one (1 ≤ n ≤ 10^9). |
Output |
Output the height of the tallest stable pyramid that may be built out of n blocks. The height must be output in hunabs. |
Sample Input |
6 5 20 |
Sample Output |
2 1 3 |
题意:给N个格子求最高能叠多少层高。每个格子底部四个方向必须有才能放。。。
题解:我们从一层开始推下去找到规律。一层最少需要1个就好了,两层把1层放上面,下面加上4个方向和上一层最底层1=5。加上上一层个数1所以是6.第三层则在第二层的基础下加上底座即可。底座格子数则是由上一层最底层+当前层*4.仔细画下图就会明白。
所以我们用两个数组递推,把所以情况枚举取来,一个代表当前最底层的数量,一个代表构建当前层最少需要多少格子。然后找到N第一次小于第几层的格子就可以找到答案是多少了。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#define LL __int64
#define EPS 1e-8
using namespace std;
int a[10000010],s[10000010];
int main()
{
a[0]=1;
s[0]=1;
for (int i=1;;i++)
{
a[i]=a[i-1]+i*4;
s[i]=s[i-1]+a[i];
if (s[i]>1000000000) break;
}
int n;
while (~scanf("%d",&n))
{
int i;
for (i=1;;i++)
if (s[i]>n)
break;
cout<<i<<endl;
}
return 0;
}