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\n",db[n]);
    }
    return 0;
}
时间: 2024-08-10 06:24:09

HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)的相关文章

HDU 2139 Calculate the formula

http://acm.hdu.edu.cn/showproblem.php?pid=2139 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 excee

HDOJ/HDU 2537 8球胜负(水题.简单的判断)

Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜.如果在打进自己颜色的所有球之前就把黑球打进,则算输.如果选手不慎打进了对手的球,入球依然有效. 现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者. 假设不会有一杆同时打进一颗黑球和其他彩球. Inp

HDOJ/HDU 2561 第二小整数(水题~排序~)

Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第一行是一个整数C,表示有C测试数据: 每组测试数据的第一行是一个整数n,表示本组测试数据有n个整数(2<=n<=10),接着一行是 n个整数 (每个数均小于100); Output 请为每组测试数据输出第二小的整数,每组输出占一行. Sample Input 2 2 1 2 3 1 1 3 Sam

hdu 1999 不可摸数 水题。

不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7966    Accepted Submission(s): 2024 Problem Description s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数. Input 包

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

HDU 5590 ZYB&#39;s Biology 水题

ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5590 Description ZYB(ZJ−267)在NOIP拿到600分之后开始虐生物题,他现在扔给你一道简单的生物题:给出一个DNA序列和一个RNA序列,问它们是否配对. DNA序列是仅由A,C,G,T组成的字符串,RNA序列是仅由A,C,G,U组成的字符串. DNA和RNA匹配当且仅当每

poj水题-1001 一个简单的大数乘幂算法实现

说到底就是一个大数乘幂运算,小数点后零.明白大数乘幂算法直接搞. 这里就有几个问题: 1.幂位数小可以用二进制容器表示(取模更好,但我是为了练习STL) 2.n位大数用string表示,外加一个int型表示小数点位置 3.字符串×字符串用小学竖式乘法算法就行,注意补零.位数多时两个string两个string地加. 代码长,但理解容易,大数乘法,加法函数很多都能重用. 1 #include <iostream> 2 #include <vector> 3 #include <

hdu 4847 Wow! Such Doge! 水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4847 统计文本中一共有多少个“Doge” 水题 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <cstdio> #includ

HDU 5578 Friendship of Frog 水题

Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5578 Description N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance betwee