杭电 - Heritage from father
来源:互联网 发布:php mysqli connect 编辑:程序博客网 时间:2024/06/10 01:41
Heritage from father
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131070/65535K (Java/Other)
Total Submission(s) : 29 Accepted Submission(s) : 10
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
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
130
Sample Output
1.00E01.00E1
Hint
Hint
when N=1 ,There is 1 gold coins.
when N=3 ,There is 1+3+6=10 gold coins.
when N=1 ,There is 1 gold coins.
when N=3 ,There is 1+3+6=10 gold coins.
AC代码
#include <iostream>#include <iomanip>#include <cmath>using namespace std;int main(){ int n; while(cin>>n&&n>0) { double sum=n; sum=sum*(sum+1)/6.0*(sum+2); int a=log10(sum); sum=sum/pow(10,a); cout<<fixed<<setprecision(2)<<sum<<"E"<<a<<endl; } return 0;}心得:
尼玛老是时间超限我也是醉了。。。后来发现是我的循环效率不高。。。参考了一下网上的解法才做出来的。。。
图片:
0 0
- 杭电 - Heritage from father
- 【ACM】杭电1178:Heritage from father 小心溢出!
- 数学—杭电1178 Heritage from father
- 杭电1178--Heritage from father
- Heritage from father
- Heritage from father
- Heritage from father
- Heritage from father
- HDU Heritage from father
- 1178 hdu Heritage from father
- hdu 1178 Heritage from father
- HDU 1178 Heritage from father
- HDU 1178 Heritage from father
- HDU 1178Heritage from father
- HDU 1178 Heritage from father
- hdu---1178Heritage from father
- hdu1178数学题 Heritage from father
- hdu(1178)Heritage from father
- c#怎么实现chart柱状图的不同颜色
- POJ 1276 Time Machine【多重背包】
- Python实现多叉树【转自百度知道】
- 一些iOS常用的第三方库和控件
- ADO.NET 从DataTable中获取某列含有的不重复值的几种方式
- 杭电 - Heritage from father
- 各种类型转换 C++
- 记录我的Android学习
- android viewpager中的fragment 延迟加载数据
- vs2010新加一个多工程的解决方案
- VS2013和Oracle10
- 多线程的那点儿事(之C++锁)
- cocos2dx:C++层通过JniHelper调用JAVA层代码进而调用Android手机应用接口
- namespace 名字空间