zoukankan      html  css  js  c++  java
  • HDU ACM 1178 Heritage from father

    Heritage from father

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 3827    Accepted Submission(s): 1350

    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.
     
    Source
     
    Recommend
    JGShining
     
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int n, m;
        double sum, result;
        while(scanf("%d",&n)== 1 && n)
        {
            sum = 1.0 * n * (n+1) * (n+2) / 6;
            m = (int)log10(sum);
            result = sum/pow(10,m);
            printf("%.2lfE%d\n", result, m);
        }
        return 0;
    }

    解题报告:
    怎么说呢?承认自己的无知和错误为什么是件很难做到的事情!

    插入自己的源代码,unsigned long long 的取值范围为:0~18446744073709551615,即0~(2^64 -1)大概为10的19次方,相比之下,double的取值范围为:0以及2.3*10^-308~1.7*10^308完全足够存储2147483647(2^31-1)的3次方,所以用unsigned long long 远远不够 !

    从这题中能够学到的东西是:1> 第一次用sprintf;2>学会了用math函数中的pow和log,3>温习了科学计数法的输出格式;从人本身这个角度来看,自己出现的问题仍然存在,一是不懂得如何分析出现错误的情况从而容易焦急且无从下手,情绪化不知道哪里是Point导致滞留在同一问题上从而浪费大量时间;二是不懂得事后总结,比如说所花的时间值不值得,遇见问题时如何抉择才能使损失的最小;三是做题少,书看得少,阅历和经验不够,这也是最重要和最需解决的。

  • 相关阅读:
    asp.net导出数据到execl并保存到本地 不需要调用Office组件
    动态创建DataTable,GridView创建多表头,表头跨行或跨列合并,创建计算列及列内容自适应等
    Oracle内置SQL函数收集整理大全
    无比强大的GridView,表头固定,表体有滚动条可滚动
    很不错的asp.net文件上传类c# 搜索文件 移动文件 删除文件等
    【备用】非常不错的ASP操作数据库类,支持多数据库MSSQL,ACCESS,ORACLE,MYSQL等
    Asp.Net读取Execl常见问题收集
    经常用到的交叉表问题,一般用动态SQL能生成动态列
    C# asp.net中常见的字符串处理函数及数字格式化
    比较两个DataTable中不同的记录,且合并两个DataTable的列显示,有图
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2755537.html
Copyright © 2011-2022 走看看