Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
1
Output
1
Input
25
Output
4

程序分析:此题的考点还是在于累加。第一次是1,第二次就是1+2,第三次就是1+(1+2)+3如此循环,所以这也要求了我们应该把每一次答案放在一个数里,对于这个题目我们用数组更能够解决问题,在用一个for循环把要加的数加进来。但是应该注意的是最后我们sum-n>0的时候,我们是加到超过了n的,所以j应该减1.但是如果sum==0,则j的值就是我们要得到的值。

程序代码:

#include<cstdio>
#include<iostream>
using namespace std;
int main( )
{int a[200]={0};
int i,n,j,sum=0;
a[1]=1;
for(i=2;i<200;i++)
{
for(j=0;j<=i;j++)
a[i]+=j;
} scanf("%d",&n);
for(j=1;j<=i;j++)
{
sum+=a[j];
if(sum>n)
{ printf("%d\n",j-1);
break;
}
else if(sum==n)
{printf("%d\n",j);
break;
}
}
return 0;
}

ACM第二次比赛( C )的更多相关文章

  1. AJAX初尝试——ACM/ICPC类比赛气球管理系统

    很早之前做过一个,白板没界面,20秒暴力刷新,数据库每个team一个n列的对应n个题目的标记项,只能对单个比赛暴力把全部user_id导入单独的气球表(也就是cid=1000用这个表的话,cid100 ...

  2. [比赛总结]ACM div3 G 比赛总结

    这次题目总体感觉和做阅读理解差不多,英文题目读起来相当费劲. 另外,这次比赛整个队伍中我们三个都突出存在的问题就是,把简单问题复杂化,抓不到事物的本质,因此很容易的就被题目误导. 比如C题,明明想到了 ...

  3. ACM第二站————归并排序

    转载请注明出处,谢谢!http://www.cnblogs.com/Asimple/p/5459664.html 归并排序————二分的思想 以中间的数为基准,每次排序都将比其小[升序排](大[降序排 ...

  4. Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)

    Binomial Coeffcients TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...

  5. Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

    Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security ...

  6. ACM第二题 生理周期

    人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色.例如,智力周期的高峰,人会思维敏捷,精力容易 ...

  7. ACM第二站————STL之stack

    栈,作为一种最基础的数据结构(栈还是一种内存的存储形式,就不介绍了),在各种数据结构的题目都会间接或者直接用到. 栈是一种受到限制的线性表,其限制是仅允许在表的一端进行插入和删除运算.这也给予了栈的一 ...

  8. ACM 第二天

    A - Mishka and Contest Mishka started participating in a programming contest. There are n problems i ...

  9. 洛谷2018寒假集训tg第二次比赛第二题Princess Principal题解

    这算不算泄题啊...被kkk发现会咕咕咕吧. 题目大意:给定一个数列a,与常数n,m,k然后有m个询问,每个询问给定l,r.问在a[l]到a[r]中最少分成几段,使每段的和不超过k,如果无解,输出Ch ...

随机推荐

  1. HDU 1544 Palindromes(回文子串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. ...

  2. ZYB's Game(博弈)

    ZYB's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. Objective-c 程序结构

    类是Objective-c的核心,Objective-c程序都是围绕类进行的.Objective-c程序至少包含以下三个部分: 1.类接口:定义了类的数据和方法,但是不包括方法的实现代码. 2.类实现 ...

  4. Joel在耶鲁大学的演讲

    Joel Spolsky是一个美国的软件工程师,他的网络日志"Joel谈软件"(Joel on Software)非常有名,读者人数可以排进全世界前100名. 上个月28号,他回到 ...

  5. 字节流复制mp3文件(带缓冲区)

    //自定义的缓冲区 import java.io.*; class  MyBufferedInputStream{    private byte[] buf = new byte[1024]; pr ...

  6. php随笔4-thinkphp 学习-ThinkPHP3.1快速入门(2)数据CURD

    ThinkPHP3.1快速入门(2)数据CURD   浏览:194739 发布日期:2012/09/05 分类:文档教程 关键字: 快速入门 CURD 上一篇中,我们了解了ThinkPHP的基础部分, ...

  7. Linux学习:find、chmod、ps命令

    下面介绍下linux下find.chmod.ps这三个常见命令的使用. 这每个命令都有很多可选的参数,不同参数体现的功能不一样.我们这里不一一介绍各种参数的含义,只介绍最常见的使用场景. 一.find ...

  8. poj 3053 Fence Repair(优先队列)

    题目链接:http://poj.org/problem?id=3253 思路分析:题目与哈夫曼编码原理相同,使用优先队列与贪心思想:读入数据在优先队列中,弹出两个数计算它们的和,再压入队列中: 代码如 ...

  9. uva11722 - Joining with Friend(几何概率)

    11722 - Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one ...

  10. IllegalArgumentException 介绍

    java.lang 类 IllegalArgumentException java.lang.Object java.lang.Throwable java.lang.Exception java.l ...