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 ...
随机推荐
- 聚聚科技---PHP开发笔试题及答案
1. echo(), print(), print_r()的区别? echo是PHP语言结构, print和print_r是函数.语言结构没有返回值,函数可以有返回值(即便没有用) . print( ...
- jquery绑定事件on的用法
语法 $(selector).on(event,childSelector,data,function,map) 参数 描述 event 必需.规定要从被选元素移除的一个或多个事件或命名空间.由空格分 ...
- [实战]记一次PUT方法拿下网站shell
第一次用方法拿shell,之前遇到的都是没有写入权限的. 站太辣鸡,纯粹练手,就不打码了. 此次实战会用到的HTTP请求方法: OPTIONS,PUT,MOVE/COPPY * 战前准备 0x01 什 ...
- c++ THUNK技术
这里想说的是:代码中的关键点为用指令jmp pFunc跳转到你想要运行的函数pFunc. 指令"jmp xxxx"占5个字节,代码中用了个一字节对齐的结构体struct Thunk ...
- android 绘图
在main.xml文件中代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- Java基础知识强化40:StringBuffer类之StringBuffer的替换功能
1. StringBuffer的替换功能: public StringBuffer replace(int start, int end, String str): 2. 案例演示: p ...
- Find命令简介
Find命令主要用于目标的搜索,尽量做到少使用,因为find会消耗大量的系统资源. 使用该命令时,需要避开服务器运行高峰期,最好在指定的小范围内进行搜索,不要轻易使用全盘搜索. Find命令常用的参数 ...
- CentOS6.X 系统安装图文教程,超详细
http://www.myhack58.com/Article/sort099/sort0102/2011/32363_7.htm
- jsp DAO设计模式
DAO(Data Access Objects)设计模式是属于J2EE体系架构中的数据层的操作. 一.为什么要用DAO? 比较在JSP页面中使用JDBC来连接数据库,这样导致了JSP页面中包含了大量的 ...
- 在div+css中用到的js代码注意return
今天做了一个项目,美工做好后放在了form中(没有加runat=server),由于用到了服务器控件,所以这里要加,否则报错,关键一段div代码是: <form id="form_re ...