cf492A Vanya and Cubes
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.
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
1
1
25
4
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;
}
}
}
cf492A Vanya and Cubes的更多相关文章
- Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 492A Vanya and Cubes
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
- Codeforces Round #280 (Div. 2) A , B , C
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces C. Vanya and Scales
C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...
- 水泡动画模拟(Marching Cubes)
Marching Cubes算法是三维离散数据场中提取等值面的经典算法,其主要应用于医学领域的可视化场景,例如CT扫描和MRI扫描的3D重建等. 算法主要的思想是在三维离散数据场中通过线性插值来逼近等 ...
- Codeforces525E Anya and Cubes(双向搜索)
题目 Source http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Toda ...
- 数论 - Vanya and Computer Game
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level ...
随机推荐
- eclipse 编码设置
eclipse 编码设置 浏览:2840 | 更新:2013-12-31 10:07 一般Java文件编码格式是UTF-8的.以下以默认GBK改为UTF-8为例. 1.改变整个工作空间的编码格式,这样 ...
- UML[1] UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)(转)
转自:http://blog.csdn.net/zhaoxu0312/article/details/7212152 继承.实现.依赖.关联.聚合.组合的联系与区别 分别介绍这几种关系: 继承 指的是 ...
- writev/readv
```cpp#include <sys/uio.h>ssize_t readv(int fd, const struct iovec *iov, int iovcnt);ssize_t w ...
- ACdream 1417 Numbers
pid=1417">题目链接~~> 做题感悟:比赛的时候用的广搜,然后高高兴兴的写完果断TLE .做题的时候不管什么题都要用笔画一下,模拟几组数据,这样或许就AC了(做题经验,有 ...
- [React] React Router: Nested Routes
Since react-router routes are components, creating nested routes is as simple as making one route a ...
- 忽略git中不需要进行版本管理的文件
在git中我们提交项目的时候有很多东西是不需要进行版本管理的,因此我们需要忽略掉. 虽然在github2.0的windows客户端提供了工具,但是这个工具并不是想象中的那么好用. 在上面点右键出现的D ...
- Android(java)学习笔记260:JNI之native方法头文件的生成
1. JDK1.6 ,进入到工程的bin目录下classes目录下: 使用命令: javah packageName.ClassName 会在当前目录下生成头文件,从头文件找到jni协议方法 下面举 ...
- Objective-C探究alloc方法的实现
OS X,iOS中的大部分作为开源软件公开在 Apple Open Source 上.虽然想让大家参考NSObject类的源代码,但是很遗憾,包含NSObject类的Foundation框架没有公开. ...
- C#--比较
类型比较: 在比较对象时,常常需要知道它们的类型,这样才能确定是否可以进行值的比较. 方法一. 可以将GetType()方法和typeof()运算符一起使用,就可以确定对象的类型. 例子: int i ...
- 使用DataSet数据集插入记录
使用INSERT语句能够完成数据插入,使用DataSet对象也可以完成数据插入.为了将数据库的数据填充到DataSet中,则必须先使用DataAdapter对象的方法实现填充,当数据填充完成后,开发人 ...