• 杭电1178 Heritage from father


    Heritage from father

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


    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
     
    这题还可以,中间用到前n项的平方和,一开始对它们的和用double型表示很费解!
    View Code
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <math.h>
     4 
     5 int main(int argc, char *argv[])
     6 {
     7     int n, bit;
     8     double sum;
     9     while( (scanf( "%d", &n )==1)&&(n!=0) )
    10     {
    11        bit = 0;
    12        sum = 1.0*n*(n+1)*(n+2)/6;
    13        while( sum >= 10 )
    14        {
    15               bit++;
    16               sum = sum / 10;    
    17        }
    18        printf( "%.2lfE%d\n", sum, bit );   
    19     }
    20   
    21   //system("PAUSE");    
    22   return 0;
    23 }
  • 相关阅读:
    【Alpha】开发日志Day30714
    【Alpha】开发日志Day10712
    实验1
    实验2
    图深度优先搜索最短路径
    一切都结束了
    C#操作XML(读XML,写XML,更新,删除节点,与dataset结合等)
    字符串匹配
    纯数学规律题
    高精度
  • 原文地址:https://www.cnblogs.com/yizhanhaha/p/3019460.html
Copyright © 2020-2023  润新知