Sum Problem
http://acm.hdu.edu.cn/showproblem.php?pid=1001
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1
5050
解题思路
很简单的求和问题
完全用循环模拟迭代也不超时,可见数据量很小。
当然也可以用求和公式来做。
下面是循环迭代模拟代码
http://acm.hdu.edu.cn/showproblem.php?pid=1001
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1
5050
解题思路
很简单的求和问题
完全用循环模拟迭代也不超时,可见数据量很小。
当然也可以用求和公式来做。
下面是循环迭代模拟代码
#include <stdio.h> #include <stdlib.h> int main (int argc, char const* argv[]) { int e, ans, i; while (scanf("%d", &e) != EOF) { ans = 0; for (i = 1; i <= e; i++) { ans += i; } printf("%d\n", ans); printf("\n"); } return 0; }
发表评论
-
fhloj1051 投票
2013-07-04 19:42 0投票 源文件: b(.bas/.c/.cpp/.pas) 输 ... -
fhloj1050 足球赛
2013-07-04 19:36 561足球赛 源文件: a(.bas/.c/.cpp/.pas) ... -
fhloj1092 五子棋
2013-07-04 12:01 668五子棋 源文件: gobang(.bas/.c/.cpp/ ... -
fhloj1091 拼单词
2013-07-04 11:53 702拼单词 源文件: words ... -
fhloj1090 21点游戏
2013-07-04 11:44 59321点游戏 源文件: poker(.bas/.c/.cpp ... -
fhloj1089 帮奶奶算帐
2013-07-04 11:17 558帮奶奶算账 源代码:bill.bas/pas 输入文件:bil ... -
hdu1019 gcd和lcm
2012-12-06 15:09 738Least Common Multiple http://a ... -
hdu1021 推理规律
2012-12-06 09:24 889Fibonacci Again http://acm.hdu ... -
hud1008 电梯 迭代模拟计算
2012-12-04 18:24 988Elevator http://acm.hdu.edu.cn ... -
hdu1000 A+B
2012-12-03 18:37 779A + B Problem http://acm.hdu.e ... -
hdu2035 乘方取余
2012-12-02 18:02 1040人见人爱A^B http://acm.hdu.edu.cn/ ... -
hdu2034 差集
2012-12-02 17:43 812人见人爱A-B http://acm.hdu.edu.cn/ ... -
hdu2033 时间计算
2012-12-02 16:24 856人见人爱A+B http://acm.hdu.edu.cn/ ... -
HDU1003最大连续子序列和
2012-12-01 15:08 1402Max Sum http://acm.hdu.edu.cn/ ... -
hdu2081 字符串拼接
2012-12-01 14:35 775手机短号 http://acm.hdu.edu.cn/sho ... -
poj1163 树型结构动态规划和最大路径
2012-11-30 22:05 1148The Triangle http://poj.org/pr ... -
POJ1579递归函数定义
2012-11-30 21:58 807Function Run Fun http://poj.or ... -
POJ1050 最大子矩阵
2012-11-30 11:34 1152To the Maxhttp://poj.org/proble ...
相关推荐
hdu1001解题报告
杭电OJ部分答案,可以很简单的解决a+b求和问题及其他问题。
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu题目分类
自己做的HDU ACM已经AC的题目
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
HDU图论题目分类