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导致滞留在同一问题上从而浪费大量时间;二是不懂得事后总结,比如说所花的时间值不值得,遇见问题时如何抉择才能使损失的最小;三是做题少,书看得少,阅历和经验不够,这也是最重要和最需解决的。

  • 相关阅读:
    wtl 支持托拽文件并在ListBox框中显示文件路径的方法
    提升本程序进程优先级和权限(VC++源代码)
    Win7下运行VC程序UAC权限问题
    Flex中带for的循环
    Flex注释
    Flex建立编译环境
    Flex事件驱动机制
    Flex应用程序的系统开发周期
    Linux下c开发 之 线程通信
    将 Win32 C/C++ 应用程序迁移到 POWER 上的 Linux,第 1 部分: 进程、线程和共享内存服务
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2755537.html
Copyright © 2011-2022 走看看