HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
2024-08-25 12:19:10
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;
}
最新文章
- SQL拼接自己需要的字符串
- node.js下使用RSA加密事例(windows)
- DEELX 正则表达式引擎(v1.2)
- VC运行库合集2005/2008/2010/2012/2013/2015
- Yii2的view需要链接跳转
- linux查找目录下的所有文件中是否含有某个字符串
- Redis集群搭建&;访问
- sql基础查询语句
- Codeforces Round #240 (Div. 2)->;A. Mashmokh and Lights
- 前端JS开发框架-DHTMLX
- ArcMAp对线要素进行平滑处(打断)
- asp.net网站发布到服务器GET的技能
- C# Memcached缓存
- 你知道BFC、IFC、FFC、GFC及多栏自适应布局吗?
- .Net开发之旅(一个年少轻狂的程序员的感慨)
- android:shape 设置圆形
- java news website
- Scala学习笔记——样本类和模式匹配
- UIView常见方法
- Ubuntu16.04 上安装MySQL5.7