Codeforces 471C

数学规律题

通过观察可以得出想要堆成i层高的塔至少需要卡牌数量为i*(3*i+1)/2,要求卡牌不能剩余,多余的卡牌如果是3 的倍数就可以摆在最下面,所以只需要遍历所能摆成最高的塔之间的所有层数即可

#include <iostream>//数据输入输出流
#include <string.h>//字符串操作函数
#include <stdio.h>//C的输入输出
#include <stdlib.h>//定义杂项函数及内存分配函数
#include <math.h>//C中的数学函数
#include <cstring>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor容器
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如:bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数(代替运算符)
//#include <iomanip.h>//参数化输入/输出
#include <limits.h>//定义各种数据类型最值常量
//#include <strstrea.h>//基于数组的输入/输出
//#include <fstream.h>//文件输入/输出
#define ll long long

using namespace std;

ll n;

ll cal ( ll i )
{
    return i * ( 3 * i + 1 ) / 2;
}

int main()
{
    cin >> n;
    ll num=0;
    for ( ll i = 1; cal ( i ) <= n; i++ )
    {
        if ( ( n - cal ( i ) ) % 3 == 0 )
        {
            num++;
        }
    }
    cout<<num<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值