Codeforces Round #280 (Div. 2)A. Vanya and Cubes(简单计算)

题目链接
题意:搭积木,告诉你第i层需要i*(i+1)/2个,然后给你总数n个,问你可以搭几层
题解:直接计算


#define CF
#ifndef CF
#include
#include
#include
#include
#include
#include
#include
#include
#else
#include
#endif // CF
using namespace std;
#define LL long long
#define pb push_back
#define X first
#define Y second
#define cl(a,b) memset(a,b,sizeof(a))
typedef pair<long long ,long long > P;
const int maxn=100005;
const LL inf=1LL<<60;
const LL mod=1e9+7;

int main(){
    int n;scanf("%d",&n);
    int ans=0,i=1,sum=0;
    while(true){
        sum+=i*(i+1)/2;
        if(sum>n){
            printf("%d\n",i-1);
            return 0;
        }
        i++;
    }
    return 0;
}

你可能感兴趣的:(CF,模拟)