Codeforces Round #280 (Div. 2) A

题目:

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:

没啥好说的。模拟一下就可以了,还wa一发不应该..

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <limits>
#include <map>

using namespace std;

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define F(i, n) for(int (i)=0;(i)<(n);++(i))
#define REP(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define UREP(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define REPOK(i, s, t, o) for(int (i)=(s);(i)<=(t) && (o);++(i))
#define MEM0(addr) memset((addr), 0, sizeof((addr)))

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398

#define MAXN 100000
#define MAXM 10000
#define MOD 1000000007

typedef long long LL;

const double maxdouble = numeric_limits<double>::max();
const double eps = 1e-10;
const int INF = 0x7FFFFFFF;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int base = 1;
    while (n >= base)
    {
        ++ans;
        n -= base;
        base += ans+1;
    }
    cout << ans;
    return 0;
}
时间: 2024-10-18 13:22:01

Codeforces Round #280 (Div. 2) A的相关文章

Codeforces Round #280 (Div. 2)

A. Vanya and Cubes 手速不够快,被别人抢先了... #include<bits/stdc++.h> #define eps 1e-9 #define FOR(i,j,k) for(int i=j;i<=k;i++) #define MAXN 1005 #define MAXM 40005 #define INF 0x3fffffff using namespace std; typedef long long LL; int i,j,k,n,m,x,y,T,ans,bi

Codeforces Round #280 (Div. 2) 解题报告 A.B.C.D.E.

不知道到底是我的水平提高了还是CF的题目变水了...... A - Vanya and Cubes 水题..暴力枚举就可以.. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include &l

Codeforces Round #280 (Div. 2) B

题目: B. Vanya and Lanterns time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system wi

Codeforces Round #280 (Div. 2) C

题目: C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark fo

Codeforces Round #280 (Div. 2) D

题目: D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's

Codeforces Round #280 (Div. 2 A,B,C,D,E)

改了时区之后打cf更辛苦了啊...昨天没做,今天补了一下啊. A. Vanya and Cubes 每次加的数规律性很明显就是:(i+1)*i/2.暴力枚举i就可以得到答案. #include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿