zoukankan      html  css  js  c++  java
  • HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    看到这个时间,我懵逼了。。。
    果然,Java就是打表,都不能AC,因为Java的输入是流,需要的时间比C真的长好多。。。。

    Problem Description
    You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.

    Input
    In each case, there is an odd positive integer n.

    Output
    Print the sum. Make sure the sum will not exceed 2^31-1

    Sample Input
    3

    Sample Output
    10

    简单题,就不翻译了。
    附上AC的C语言代码:

    #include<iostream>
    const int MAX=2345;
    //计算2345正好大于2^31-1,输入输出用scanf和printf不能cin和cout不然超时
    __int64 db[MAX];
    using namespace std;
    int main()
    {
        int n,m,i;
        db[1]=1;
        //打表法 
        for(i=3;i<=MAX;i+=2)
        {
            db[i]=db[i-2]+i*i;
        }
        while(scanf("%d",&n)!=EOF)
        {
            printf("%I64d
    ",db[n]);
        }
        return 0;
    }
  • 相关阅读:
    mysql关联查询
    文本框,下拉框,单选框只读状态属性
    sql索引实例
    sql视图实例
    SQL触发器实例
    存储过程实例
    sql 、linq、lambda 查询语句的区别
    LINQ中的一些查询语句格式
    面试宝典
    SQL常用语句
  • 原文地址:https://www.cnblogs.com/webmen/p/5739226.html
Copyright © 2011-2022 走看看