• 2013暑假集训B组训练赛第二场


    B - Funky Numbers
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.

    A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

    Input

    The first input line contains an integer n (1 ≤ n ≤ 109).

    Output

    Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

    Sample Input

    Input
    256
    Output
    YES
    Input
    512
    Output
    NO


    一开始开了个10^9的数组,结果mle
    后来改了还是tle
    然后继续怎么都过不了
    然后一把乱改,结果改好了。。。= =
    心酸;
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    const long long MAXN = 1000000005;
    
    int num;
    int f[50000];
    int n;
    
    void build()
    {
        n = 0;
        int k;
        for(int i = 1; k < MAXN; i++)
        {
            k = i*(i+1)/2;
            f[n++]= k;
        }
    }
    
    
    int main()
    {
        build();
        n--;
        while(~scanf("%d",&num))
        {
            bool is = 0;
            for(int i = 0; f[i] < num; i++)
            {
                int id = lower_bound(f, f + n,num - f[i]) - f;
    
                if(f[id] == num - f[i])
                {
                    is = true;
                    break;
                }
            }
            printf("%s
    ", is ? "YES" : "NO");
        }
        return 0;
    }
  • 相关阅读:
    C#Socket发16进制以及进制转换
    WPF跨线程操作UI界面控件
    DispatcherTimer和Timer的区别
    C#等比列放大缩小图片
    计算进项税
    AX 中通过SqlServer数据库刷数据
    AX中日期的常用方法
    从AX2012系统批量生成CSV格式数据
    装箱单过发票
    导入CSV文件乱码
  • 原文地址:https://www.cnblogs.com/wejex/p/3219485.html
Copyright © 2020-2023  润新知