本文共 728 字,大约阅读时间需要 2 分钟。
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-1Sample Input
3Sample Output
10简单题,就不翻译了。
附上AC的C语言代码:#includeconst 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;}
转载地址:http://krbnl.baihongyu.com/