zhber
有好多做过的题没写下来,如果我还能记得就补吧
A. Vanya and Cubes
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.

Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

Input

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

Output

Print the maximum possible height of the pyramid in the single line.

Sample test(s)
input
1
output
1
input
25
output
4
Note

Illustration to the second sample:

 

 

就是sb模拟了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,tot;
int s[100010];
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		s[i]=s[i-1]+i;
		tot+=s[i];
		if (tot>n)
		{
			printf("%d\n",i-1);
			return 0;
		}
		if (tot==n)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}

 

posted on 2014-12-02 07:36  zhber  阅读(235)  评论(0编辑  收藏  举报