注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU 1178Heritage from father  

2014-03-31 14:45:42|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
/*科学计数法的表示挺多的:
c++的函数:
cout<<setiosflags(ios::fixed)<<setprecision(2)<<pow(10,a)<<'E'<<int(b)<<endl;
也可以对求和结果sum,处理
c=0;
while (sum>=10)
{
c++;
sum/=10;
}
printf ("%.2lfE%d\n",sum,c);
*/
1^2+2^2+3^2...+N^2 = N*(N+1)*(2N+1)/6             .......等式1
1+2+3...+N=N*(N+1)/2             .......等式2
(等式1+等式2)/2 = N*(N+1)*(N+2)/6 


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


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

#include<stdio.h>

int main()
{
int n,k;
double sum;
while(scanf("%d",&n),n)
{
sum=0;
k=0;
sum=1.0*n*(n+1)/6.0*(2+n);
while(sum>=10)
{
sum/=10;
k++;
}
printf("%.2lfE%d\n",sum,k);

}
return 0;
}


 

  评论这张
 
阅读(5)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017