zoukankan      html  css  js  c++  java
  • cf492A Vanya and Cubes

    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
    ",i-1);
    			return 0;
    		}
    		if (tot==n)
    		{
    			printf("%d
    ",i);
    			return 0;
    		}
    	}
    }
    
    ——by zhber,转载请注明来源
  • 相关阅读:
    二次冲刺站立会议五
    二次冲刺站立会议四
    二次冲刺站立会议三
    二次冲刺站立会议二
    自己常用网址导航
    Eclipse几个配置
    JVM参数和jvm.log
    JVM性能监控命令
    Linux基本信息查看命令
    Linux IO性能监控工具
  • 原文地址:https://www.cnblogs.com/zhber/p/4136458.html
Copyright © 2011-2022 走看看