湖大训练赛第十场 Aztec Pyramid

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值