HDU Heritage from father

Heritage from father

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131070/65535K (Java/Other)
Total Submission(s) : 71   Accepted Submission(s) : 18

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.

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

Gardon-DYGG Contest 1

简单来说就是求an=n*(n+1)/2的前n项和。

AC代码:

#include <iostream>
#include <cstdio>
#include<math.h>
using namespace std;
int main()
{
    double n,a,m,b;
    while(scanf("%lf",&n)!=EOF&&n!=0)
    {
        b=log10(n*1.0/6)+log10((n+1)*1.0)+log10((n+2)*1.0);
        a=b-(int)(b);
        m=pow(double(10),a);
        printf("%.2lfE%d\n",m,(int)(b));
    }
    return 0;
}
时间: 2024-11-04 09:17:47

HDU Heritage from father的相关文章

hdu 1178 Heritage from father (推导)

题意: 有一个金币堆的金字塔,最上层就有一个金币,以后的i层都是边长为i的实心三角形,给你层数,问:一共有多少个金币?(用科学计数法表示,并且保留两位小数) 解题思路: 根据题意可知求出1*n+2*(n-1)+3*(n-2)+4*(n-3)+.......+(n-2)*3+(n-1)*2+n*1的和即可,但是要化简一下求出n*(n+1)*(n+2)/6; 证明: 1 * n + 2 (n - 1) + 3 (n - 2) + …… + (n - 2) * 3 + (n - 1) * 2 + n

一些项目——Heritage from father

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

hdoj-1178-Heritage from father【科学计数法表示】

Heritage from father Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 6076 Accepted Submission(s): 2214 Problem Description Famous Harry Potter,who seemd to be a normal and poor boy,is actually a

[hiho 13]最近公共祖先 一

题目描述 由于这个跟后几周是一个系列,这周的做法比较简单. 把第一个人的所有祖先做标记,第二个人向上查找祖先直到找到一个标记过的节点或无法继续为止. 代码其实没什么意思. import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { private static class Person { String name; String father; boolean tag

HDU 6141 I am your Father!(最小树形图)

[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6141 [题目大意] 给出一个有向图,求1点为根的最小树形图使得第n个点的直接父亲编号最小 [题解] 如果没有第n个点直接父亲编号最小的要求, 那么只要跑一遍朱刘算法即可,考虑到直接父亲最小的条件, 我们连向第n个点的所有边进行加权操作, 使得其在总边权相同的情况选取答案具有优先性 [代码] #include <cstdio> #include <algorithm> using n

HDU 6141 I am your Father!(最小树形图+权值编码)

http://acm.hdu.edu.cn/showproblem.php?pid=6141 题意: 求最大树形图. 思路: 把边的权值变为负值,那么这就是个最小树形图了,直接套模板就可以解决. 有个问题就是n结点的父亲结点的编号要尽量小,这里有个技巧可以用,权值编码,将所有边的权值都放大1000倍,对于和n相连的边,每条边在减去(n-u)的权值.这样就会去优先考虑编号小的边,而且因为权值最大为100,所以扩大1000是不会影响结果的. 1 #include<iostream> 2 #incl

hdu 1856 More is better(并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 18985    Accepted Submission(s): 6990 Problem Description Mr Wang wants some

LCA(最近公共祖先)--tarjan离线算法 hdu 2586

HDU 2586 How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11320    Accepted Submission(s): 4119 Problem Description There are n houses in the village and some bidirectional roads c

HDU 4313 Matrix(贪心+并查集)

HDU 4313 题意: 有n个节点,n-1条边,其中k个节点为危险节点,有大规模杀伤性武器,切断哪些路能使得这些大规模杀伤性武器的危险节点之间彼此不连通,且切断的边权值之和最小. 思路: 初始化每个节点为一个集合,并记录每个集合中危险节点的数目(0或1). 要实现权值之和尽可能的小,则要权值尽可能小,故先将n-1条边按权值先升序排序. 排序后枚举这些边: 若边的两端节点所在集合均有大规模杀伤性武器,则删除它并累计其权值. 若只有一边有,则合并这两个集合(用并查集),合并时尽可能将危险节点置于父