我觉得做这个题 最大的意义就是通过NNNN次的WA让我反复而深刻地体会到了 计算过程中也会溢出 这种错误。。。。

另外要把一个数用科学计数法表示,只需要两步:

1、对这个数取以10为底的对数,其结果取整就是科学计数法中10需要的指数。

2、用这个数除以 【10 ^ (步骤一的结果)】就是科学计数法的有效数字。

代码:

#include <stdio.h>
#include <math.h>/* Sn = n(n+1)(n+2)/6; */int main(int argc, char *argv[])
{int N;while(scanf("%d",&N) != EOF && N != 0){/*    double sum = N * (N + 1) / 6.0 * (N + 2);  第一句开始我是这样写的,结果老是WA .注意,N * (N + 1) 这个结果会溢出 */double sum = N * ((N + 1) / 6.0) * (N + 2); /* 因此要先计算 (N + 1) / 6.0 ,这样数就小了,不会溢出了 */int bit = (int)log10(sum);double head = sum / pow(10,bit);printf("%.2lfE%d\n",head,bit);}return 0;
}
Problem Description
Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wizard.Everything changed when he had his birthday of ten years old.A huge man called 'Hagrid' found Harry and lead him to a new world full of magic power. 
If you've read this story,you probably know that Harry's parents had left him a lot of gold coins.Hagrid lead Harry to Gringotts(the bank hold up by Goblins). And they stepped into the room which stored the fortune from his father.Harry was astonishing ,coz there were piles of gold coins. 
The way of packing these coins by Goblins was really special.Only one coin was on the top,and three coins consisted an triangle were on the next lower layer.The third layer has six coins which were also consisted an triangle,and so on.On the ith layer there was an triangle have i coins each edge(totally i*(i+1)/2).The whole heap seemed just like a pyramid.Goblin still knew the total num of the layers,so it's up you to help Harry to figure out the sum of all the coins.
Input
The input will consist of some cases,each case takes a line with only one integer N(0<N<2^31).It ends with a single 0.
Output
对于每个输入的N,输出一行,采用科学记数法来计算金币的总数(保留三位有效数字)
Sample Input
1 3 0
Sample Output
1.00E0 1.00E1

Hint

Hint

when N=1 ,There is 1 gold coins. when N=3 ,There is 1+3+6=10 gold coins.

【ACM】杭电1178:Heritage from father 小心溢出!相关推荐

  1. 5410 ACM 杭电 01+完全背包

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5410 虽然是英文题目:但还是很好理解的.明显的背包问题 思路:如果你能想到把题目拆分成小问题,就会简单许多 ...

  2. 最详细最简单:最大公因数求法、辗转相除法、更相减损法,入门ACM,杭电水题,算法递归,初级算法题一看就懂

    文章目录 前言 一.名称定义 1.最大公约数 2.辗转相除法 3.更相减损法 二.ACM杭电入门题 1.解题思路 三.解题参考代码(C语言,C++) 0.最优算法(C++) 1.辗转相除求解(C语言) ...

  3. 杭电OJ分类题目(2)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...

  4. 杭电ACM(HDUOJ)试题分类

    杭电ACM试题分类 第一篇 1001 这个就不用说了吧                      1002 简单的大数                            1003 DP经典问题,最 ...

  5. 杭电acm第2304题答案c语言,【转】杭电ACM试题分类

    注:网上搜的 第一篇 1001 这个就不用说了吧 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 ...

  6. 杭电ACM题目类型整理

    版权声明:(╯3╰) 转载请注明: http://blog.csdn.net/bat67 杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 10 ...

  7. 【杭电ACM】1097 A hard puzzle

    [杭电ACM]1097  A hard puzzle http://acm.hdu.edu.cn/showproblem.php?pid=1097 先用int手写了算法结果竟然wrong answer ...

  8. 杭电ACM刷题(1):1002,A + B Problem II

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  9. 杭电acm2151题java的解法,杭电ACM题型分类

    杭电ACM题型分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1 ...

最新文章

  1. mysql killed进程不结束_php和mysql连接方式(短 长 池)
  2. 【NodeJS 学习笔记04】新闻发布系统
  3. 第2周项目2程序的多文件组织
  4. 半潜式平台及其动力定位系统
  5. 反三角函数怎么表示_交流电的功率因数怎么算(里面有例子)
  6. OrganicsDelivery总结
  7. Java中CAS详解
  8. Linux 命令之 grep -- 强大的文本搜索工具/正则表达式搜索
  9. java拖动图片拼图_求教,我的这个拼图程序中的移动图片的改怎么做
  10. 8、TypeScript-解构赋值
  11. 顺丰控股:2月速运物流业务营业收入98.49亿元,同比下降3.36%
  12. 利用格林函数解泊松方程
  13. 堆排序时间复杂度的计算过程
  14. DOCKER镜像仓库地址
  15. 计算机工作组如何添加打印机,局域网添加打印机,详细教您局域网打印机怎么添加...
  16. Python开发系列课程(14) - 玩转正则表达式
  17. PyTorch系列 | correct += (predicted == labels).sum().item()的理解
  18. 永久短网址生成 可以永久使用的短链接推荐
  19. 【定位原理揭秘第三期】室内定位技术原理揭秘
  20. word插入和删除水印

热门文章

  1. EclipseMars + Maven + SpringMVC + Tomcat7
  2. Row有争吵吵闹的意思
  3. 2012年宝兰德软件技术服务有限公司三句半节目台词
  4. 触角云开发的微信商城系统
  5. 收藏的技术资料下载网址
  6. java学习2022-6-6
  7. 《3D数学基础》提炼总结(一)3D数学和笛卡尔坐标系
  8. verilog实现有符号数求绝对值
  9. HTTP中的content-type的几种取值分析
  10. 张凯龙 西北工业大学计算机学院,西北工业大学计算机学院研究生不在校管理规定...